在android中的另一个视图上方放置/重叠(z-index)一个视图 [英] Placing/Overlapping(z-index) a view above another view in android

查看:70
本文介绍了在android中的另一个视图上方放置/重叠(z-index)一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 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 上,over"我的意思是 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(最好是线性布局)将一个视图置于另一个视图之上?

I want to know how can we place one view above the other, with varying z-index (preferably in linear layout) ?

推荐答案

你不能为此使用 LinearLayout,但你可以使用 FrameLayout.在 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="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 的顶部,沿着图像的底部中心.

In this instance, the TextView would be drawn on top of the ImageView, along the bottom center of the image.

这篇关于在android中的另一个视图上方放置/重叠(z-index)一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆