【发布时间】:2015-12-01 23:06:27
【问题描述】:
我有 5 张图片应该水平放置在线性布局中,并且应该以合理的方式放置,第三张图片位于屏幕的中心。所有图像的宽度和高度都相同。
即图像之间的填充应该动态调整。
谢谢
【问题讨论】:
-
我建议你在这种情况下使用相对布局。
标签: android android-layout alignment android-linearlayout
我有 5 张图片应该水平放置在线性布局中,并且应该以合理的方式放置,第三张图片位于屏幕的中心。所有图像的宽度和高度都相同。
即图像之间的填充应该动态调整。
谢谢
【问题讨论】:
标签: android android-layout alignment android-linearlayout
你可以使用
android:layout_weight="1"
对于您的每个项目,这将解决您的问题并在屏幕中使用相等的空间排列项目
【讨论】:
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff5678" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff5678" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff5678" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff5678" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff5678" />
</LinearLayout>
Beetwen 每个 ImageView 添加空 View 参数:android:layout_width="0dp"
android:layout_weight="1"
【讨论】:
【讨论】: