我需要设计下面给出的 Andorid 布局,但是我无法正确处理定位。
这里是 View 部分的类型和我的约束:
- A: ImageView ,固定宽度,固定高度,左对齐
- B: TextView ,自动缩放宽度,固定高度
- C: TextView ,自动缩放宽度,固定高度
- D: TextView ,自动缩放宽度,固定高度
- E: TextView ,自动缩放宽度,固定高度
- F: ImageView ,固定宽度,固定高度,右对齐
我尝试了相对布局,但我无法处理最右边的 View (即 F)。那么这个布局的正确 XML 标记应该是什么?
最佳答案
相当简单。尝试这样的操作(为了节省空间,我省略了高度和宽度等其他内容):
<RelativeLayout>
<ImageView
android:id="@+id/A"
android:layout_alignParentLeft="true" />
<ImageView
android:id="@+id/F"
android:layout_alignParentRight="true" />
<LinearLayout
android:id="@+id/container"
android:layout_toRightOf="@+id/A"
android:layout_toLeftOf="@+id/F"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="@+id/B"
android:layout_weight="1" />
<TextView
android:id="@+id/C"
android:layout_weight="1" />
<TextView
android:id="@+id/D"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="@+id/E"
android:layout_toRightOf="@+id/A"
android:layout_toLeftOf="@+id/F"
android:layout_below="@+id/container" />
</RelativeLayout>
关于Android 相对布局缩放和对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9181460/