简体   繁体   English

Android:如何在布局已经包含按钮的情况下以编程方式通过视图覆盖整个布局?

[英]Android: How to cover the whole layout by a view programatically while the layout contains buttons already?

I've a linear layout filled by buttons(view1 - view5).我有一个由按钮填充的线性布局(view1 - view5)。

I would like to add a view(red star) to this layout and I want this red star to cover the whole layout and its buttons (without setting the visibility of them)我想在这个布局中添加一个视图(红星),我希望这个红星覆盖整个布局及其按钮(不设置它们的可见性)

in the attached image:在附图中:

1 - the layout I've, filled by buttons 1 - 我的布局,由按钮填充

2- the layout I want to achieve by adding my red star programmatically 2-我想通过以编程方式添加我的红星来实现的布局

How can I do so?我怎么能这样做? 在此处输入图片说明

First switch the root layout to a RelativeLayout, something like首先将根布局切换为RelativeLayout,类似

<RelativeLayout ...>
    <View android:id="@+id/view1"
          ... />
    <View android:id="@+id/view2"
          ... 
          android:layout_below="@id/view1" />
    <View android:id="@+id/view3"
          ...
          android:layout_toRightOf="@id/view2"
          android:layout_below="@id/view1" />
    ...

Then at the bottom of that layout add your overlay which ignores all the other views (so can draw over them)然后在该布局的底部添加忽略所有其他视图的叠加层(因此可以绘制它们)

    <View android:id="@+id/overlay"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true" />
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM