Android - 并排放置两个 ImageView,中间留有空白
Android - Place two ImageView's side by side with margin in between
这就是我想要的:
左图 45%,中图 10%,右图 45%,所有的高度都应该与宽度成比例
这是我试过的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView13">
<ImageView
android:id="@+id/imageLeft"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:src="@drawable/placeholder_white" />
<ImageView
android:id="@+id/margin"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:src="@drawable/placeholder_white" />
<ImageView
android:id="@+id/imageRight"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:src="@drawable/placeholder_white" />
</LinearLayout>
但结果是废话
我该怎么做?我需要使用 Table 布局吗?
提前致谢
您需要为每个 child 设置 android:layout_width="0dp"
到 LinearLayout 并将 LinearLayout 的 android:layout_height="0dp"
替换为 android:layout_height="wrap_content"
并为每个 [= 设置具体的 android:layout_heigh
27=]。例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ImageView
android:id="@+id/imageLeft"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:adjustViewBounds="true"
android:src="@color/black" />
<ImageView
android:id="@+id/margin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:src="@color/blue" />
<ImageView
android:id="@+id/imageRight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:adjustViewBounds="true"
android:src="@color/red" />
</LinearLayout>
这就是我想要的:
左图 45%,中图 10%,右图 45%,所有的高度都应该与宽度成比例
这是我试过的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView13">
<ImageView
android:id="@+id/imageLeft"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:src="@drawable/placeholder_white" />
<ImageView
android:id="@+id/margin"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:src="@drawable/placeholder_white" />
<ImageView
android:id="@+id/imageRight"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:src="@drawable/placeholder_white" />
</LinearLayout>
但结果是废话
我该怎么做?我需要使用 Table 布局吗?
提前致谢
您需要为每个 child 设置 android:layout_width="0dp"
到 LinearLayout 并将 LinearLayout 的 android:layout_height="0dp"
替换为 android:layout_height="wrap_content"
并为每个 [= 设置具体的 android:layout_heigh
27=]。例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ImageView
android:id="@+id/imageLeft"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:adjustViewBounds="true"
android:src="@color/black" />
<ImageView
android:id="@+id/margin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:src="@color/blue" />
<ImageView
android:id="@+id/imageRight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:adjustViewBounds="true"
android:src="@color/red" />
</LinearLayout>