简体   繁体   中英

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).

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

2- the layout I want to achieve by adding my red star programmatically

How can I do so? 在此处输入图片说明

First switch the root layout to a RelativeLayout, something like

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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