два элемента в линейной компоновке упакованы по центру, а не по бокам - PullRequest
0 голосов
/ 27 февраля 2020

У меня есть такой макет:

<LinearLayout 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="wrap_content"
    android:orientation="horizontal">
  <com.google.android.libraries.onegoogle.account.particle.AccountParticle
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/part_a"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_vertical|start" />
  <ImageView
      android:id="@+id/part_b"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginEnd="14dp"
      android:layout_marginRight="14dp"
      android:layout_gravity="center_vertical|end"
      app:srcCompat="@drawable/my_image" />
</LinearLayout>

Я бы ожидал, что part_a будет выровнен по правому краю, а part_b выровнен по левому краю. (Спасибо android:layout_gravity).

Почему я вижу их упакованными закрытыми друг для друга?

enter image description here

1 Ответ

0 голосов
/ 27 февраля 2020

Использование ConstraintLayout

<android.support.constraint.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="wrap_content">
    <com.google.android.libraries.onegoogle.account.particle.AccountParticle
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/part_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
    <ImageView
        android:id="@+id/part_b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="14dp"
        android:layout_marginRight="14dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:srcCompat="@drawable/my_image" />
</android.support.constraint.ConstraintLayout>
...