配售/重叠(的z-index)以上的Android另一种观点认为视图 [英] Placing/Overlapping(z-index) a view above another view in android
问题描述
我有一个线性布局其中包括的ImageView和TextView中,人们又如下的线性布局。
I have a linear layout which consists of imageview and textview , one below another in a linear layout.
<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的另一个小文认为,通过过我的意思是z-index值超过ImageView的,我希望把这个,在中央及以上(重叠)的ImageView的。
Some rules might be missing , this is to give an idea , how layout looks. I want another small text view of say 50dip in length and width , placed over the imageview, by "over" I meant z-index more than imageview , I want to place this , in the center and above(overlapping) the imageview.
我想知道怎么才能把一个视图在另一个的上面,用不同的z-index(preferably线性布局)?
I want to know how can we place one view above the other, with varying z-index (preferably in linear layout) ?
推荐答案
您不能使用的LinearLayout这一点,但你可以使用<一个href="http://developer.android.com/reference/android/widget/FrameLayout.html"><$c$c>FrameLayout$c$c>.在的FrameLayout
的z-index值是由该项目的增加,例如为了定义的:
You can't use a LinearLayout for this, but you can use a FrameLayout
. In a FrameLayout
, the z-index is defined by the order in which the items are added, for example:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_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的顶部,沿图像的底部中心
In this instance, the TextView would be drawn on top of the ImageView, along the bottom center of the image.
这篇关于配售/重叠(的z-index)以上的Android另一种观点认为视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!