上方的第一个视图/LinearLayout中的第二个视图重叠 [英] First view above / overlapping second in LinearLayout
本文介绍了上方的第一个视图/LinearLayout中的第二个视图重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在LinearLayout中显示第一个视图与第二个视图重叠?
Is it possible to show the first view in a LinearLayout overlapping the second?
我想这样布局我的视图:
I would like to layout my views like so:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true" >
<TextView
android:id="@+id/firstTextView"
android:layout_width="wrap_content"
android:layout_height="wrapContent" />
<TextView
android:id="@+id/secondTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
但是我需要将布局中的第一个视图firstTextView放置在(重叠)secondTextView的顶部.这可能吗?我使用LinearLayout是因为我也在玩边距来获得重叠效果.
But I need my first view from the layout, firstTextView, to be placed on top of (overlapping) secondTextView. Is this possible? I am using the LinearLayout because I'm also playing with the margins to get an overlapping effect.
推荐答案
对我有用并且可能对您有用的是:
What worked for me and probably will work for you is that:
- 使用RelativeLayout(而不是LinearLayout)包装2个TextView,然后设置android:clipChildren ="false".这样可以防止重叠部分被剪切.
- 在第一个TextView下方布置第二个TextView
- 在代码中,在第一个TextView上调用BringToFront().默认情况下,第一个textview首先绘制,并将在第二个textview下方.调用BringToFront()将更改该顺序.
所以布局可以是这样的:
So the layout can be something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clipChildren="false">
<TextView
android:id="@+id/firstTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:text="First View" />
<TextView
android:id="@+id/secondTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firstTextView"
android:background="#00000000"
android:layout_marginTop="-13dp"
android:text="Second View"/>
</RelativeLayout>
和:
TextView firstTextView = (TextView)findViewById(R.id.firstTextView);
firstTextView.bringToFront();
这篇关于上方的第一个视图/LinearLayout中的第二个视图重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文