我有一个由 imageview 和 textview 组成的线性布局,在线性布局中一个在另一个之下。
<LinearLayout android:orientation="horizontal" ... >
<ImageView
android:id="@+id/thumbnail"
android:layout_weight="0.8"
android:layout_width="0dip"
android:layout_height="fill_parent">
</ImageView>
<TextView
android:id="@+id/description"
android:layout_weight="0.2"
android:layout_width="0dip"
android:layout_height="wrap_content">
</TextView>
可能缺少一些规则,这是为了给出一个想法,布局的外观。我想要另一个长度和宽度为 50dip 的小文本视图,放置在 imageview 上,“over”是指 z-index 比 imageview 更多,我想将它放置在 imageview 的中心和上方(重叠)。
我想知道我们如何将一个视图放在另一个视图之上,并具有不同的 z-index(最好是线性布局)?
原文由 sat 发布,翻译遵循 CC BY-SA 4.0 许可协议
您不能为此使用 LinearLayout,但可以使用
FrameLayout
。在FrameLayout
中,z-index 由添加项目的顺序定义,例如:在这种情况下,TextView 将绘制在 ImageView 的顶部,沿着图像的底部中心。