макет ограничения, центр, когда ширина больше максимальной ширины

у меня есть два текстовых представления. Он имеет фиксированную маржу с обеих сторон. Текст должен быть выровнен по левому краю, но на больших устройствах с упомянутой шириной> максимальной ширины текстовое представление должно быть центрировано, а не выровнено по левому краю. Я не могу получить это центрирование на больших устройствах.

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal">

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:text="@{title}"
        android:textColor="?colorShade1"
        android:textSize="60dp"
        android:layout_marginTop="20dp"
        app:layout_constraintBottom_toTopOf="@id/subTitle"
        app:layout_constraintEnd_toEndOf="@+id/guidelineEnd"
        app:layout_constraintStart_toStartOf="@+id/guidelineStart"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_max="1280dp"
        app:layout_constraintHorizontal_bias="0.0"
        tools:text="Title" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/subTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="8dp"
        android:text="@{subTitle}"
        android:textColor="?colorShade1"
        android:textSize="32dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/guidelineEnd"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/title"
        app:layout_constraintTop_toBottomOf="@+id/title"
        app:layout_constraintWidth_max="640dp"
        tools:text="SubTitleView" />

    <android.support.constraint.Guideline
        android:id="@+id/guidelineStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="64dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guidelineEnd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_end="64dp" />

</android.support.constraint.ConstraintLayout>

person png    schedule 31.10.2017    source источник
comment
Непонятно, что вы хотите или в чем проблема. Можете ли вы опубликовать некоторые визуальные рекомендации?   -  person Cheticamp    schedule 31.10.2017


Ответы (2)


Используйте 1_

Это будет центрировать LinearLayout в макете ограничения, сохраняя горизонтальное поле 40dp, пока оно не достигнет ширины 414dp:

<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="40dp"
            android:layout_marginEnd="40dp"
            app:layout_constraintWidth_max="414dp"
            android:orientation="vertical"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
person marcshilling    schedule 24.04.2020

Вам нужна копия вашего макета в папке res/layout-large со вторым макетом, который будет специфичен для больших экранов.

Подробнее см. на странице https://developer.android.com/training/multiscreen/screensizes.html в псевдонимах

person Marcos Vasconcelos    schedule 31.10.2017