Центральные виды в макете ограничения - PullRequest
0 голосов
/ 15 мая 2018

Итак, во-первых, да, здесь есть похожие посты, и я не смог решить мою проблему, прочитав их. Мне нужно центрировать две кнопки в макете ограничения, как показано ниже.

enter image description here

Кнопки расположены под несколькими метками, которые вы сможете увидеть в конце XML. В настоящее время результирующий макет выглядит следующим образом.

enter image description here

Результат, к которому я стремлюсь, похож на первое изображение, поэтому две кнопки должны быть центрированы под текстовым представлением с надписью «Без местоположения».

Я довольно новичок в использовании макетов ограничений. Я читал, используя "layout_constraintHorizont_bias", это был лучший подход, но мне не повезло с этим. Xml для моего макета ниже, любая помощь или руководство высоко ценится.

   <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:gravity="center_vertical|center"
        android:layout_height="wrap_content"
        android:id="@+id/checkIn_layout">
        <TextView
            android:id="@+id/checkIn_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="Manual Check-in"
            android:textColor="#FFFFFF"
            android:textSize="16dp"
            android:textStyle="normal"
            android:fontFamily="sans-serif"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
        <TextView
            android:id="@+id/checkIn_duration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="00:00:00"
            android:textColor="#FFFFFF"
            android:fontFamily="sans-serif-medium"
            android:textSize="50dp"
            android:textStyle="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/checkIn_title" />
        <TextView
            android:id="@+id/checkIn_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:drawableLeft="@drawable/icon_location"
            android:drawablePadding="5dp"
            android:text="Glow New Media"
            android:textColor="#FFFFFF"
            android:fontFamily="sans-serif"
            android:textSize="16dp"
            android:textStyle="normal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/checkIn_duration" />
        <Button
            android:id="@+id/checkIn_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Check Out"
            android:paddingLeft="25dp"
            android:paddingRight="25dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/RoundedButton"
            android:textColor="#399AEA"
            android:textSize="16dp"
            android:fontFamily="sans-serif-medium"
            android:textStyle="normal"
            android:padding="10dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@+id/onduty_button"
            app:layout_constraintTop_toBottomOf="@+id/checkIn_location"
            app:layout_constraintHorizontal_bias="0.5" />
      <ImageButton
        android:id="@+id/onduty_button"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:padding="10dp"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_power"
        android:background="@drawable/PowerButton"
        app:layout_constraintTop_toBottomOf="@+id/checkIn_location"
        app:layout_constraintLeft_toRightOf="@+id/checkIn_button"
        app:layout_constraintHorizontal_bias="0.5" />
    </android.support.constraint.ConstraintLayout>

1 Ответ

0 голосов
/ 15 мая 2018

Используйте только один набор; либо влево-вправо , либо начало, конец . Теперь добиться того, что вы пытаетесь, - именно то, что делает chainStyle. Проверьте документы для справки (см. Концепции цепочки из ссылки).

То, что вам нужно, это packed как HorizontalChainStyle.

Вы можете сделать это так:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/checkIn_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center"
tools:background="@color/blue">

<TextView
    android:id="@+id/checkIn_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:fontFamily="sans-serif"
    android:text="Manual Check-in"
    android:textColor="#FFFFFF"
    android:textSize="16dp"
    android:textStyle="normal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/checkIn_duration"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:fontFamily="sans-serif-medium"
    android:text="00:00:00"
    android:textColor="#FFFFFF"
    android:textSize="50dp"
    android:textStyle="normal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/checkIn_title" />

<TextView
    android:id="@+id/checkIn_location"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:drawableLeft="@drawable/ic_email"
    android:drawablePadding="5dp"
    android:fontFamily="sans-serif"
    android:text="Glow New Media"
    android:textColor="#FFFFFF"
    android:textSize="16dp"
    android:textStyle="normal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/checkIn_duration" />

<Button
    android:id="@+id/checkIn_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@color/white"
    android:fontFamily="sans-serif-medium"
    android:padding="10dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:text="Check Out"
    android:textColor="#399AEA"
    android:textSize="16dp"
    android:textStyle="normal"
    app:layout_constraintEnd_toStartOf="@+id/onduty_button"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/checkIn_location" />

<ImageButton
    android:id="@+id/onduty_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="#FF0000"
    android:padding="10dp"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:src="@android:drawable/ic_lock_power_off"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/checkIn_button"
    app:layout_constraintTop_toBottomOf="@+id/checkIn_location" />

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...