我有一个线性布局,它由图像视图和文本视图组成,在线性布局中一个位于另一个下方。
<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>
一些规则可能会丢失,这是为了给出一个想法,布局看起来是什么样子。我想要另一个小的文本视图,长度和宽度都是50点,放在imageview上," over“我指的是z-index而不是imageview,我想把这个放在imageview的中心和上方(重叠)。
我想知道如何将一个视图放在另一个视图之上,并使用不同的z索引(最好是线性布局)?
发布于 2011-01-14 04:41:21
为此,您不能使用LinearLayout,但您可以使用FrameLayout
。在FrameLayout
中,z索引由项的添加顺序定义,例如:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_drawable"
android:scaleType="fitCenter"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:padding="5dp"
android:text="My Label"
/>
</FrameLayout>
在本例中,TextView将沿着图像的底部中心绘制在ImageView的顶部。
发布于 2011-09-07 18:23:42
发布于 2012-02-24 08:03:22
RelativeLayout的工作方式相同,相对布局中的最后一个图像获胜。
https://stackoverflow.com/questions/4182486
复制相似问题