2013-03-15 82 views
0

如何创建布局,就像我在任何布局中以普通背景的形式附加布局。当我单击任何布局或返回到该布局时,布局布局应带有任何表单字段按钮或文字...任何如何在android中创建覆盖布局

在此先感谢。

enter image description here

+0

你想交换布局可见性或什么是你的最终目标? – g00dy 2013-03-15 11:24:43

+0

我的意思是,在布局底部Airtel text.Ff我触摸,数字布局想要up.Again clcik相同的数字布局需要向下隐藏。类似于android的keybowrd显示(如果单击文本框的android keybord将滑动相同的效果) – Subha 2013-03-18 08:08:33

+0

可能重复的[Android覆盖视图ontop一切?](http://stackoverflow.com/questions/7519160/android-overlay-a -view-on-of-everything) – 2016-10-02 19:13:51

回答

4

使用RelativeLayout或FrameLayout。最后一个子视图将覆盖其他所有内容。

为确保叠加视图位于顶部,您可以在相对布局上调用ViewGroup.bringChildViewToFront()

实施例:

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/root_view"> 

    <EditText 
     android:layout_width="fill_parent" 
     android:id="@+id/editText1" 
     android:layout_height="fill_parent"> 
    </EditText> 

    <EditText 
     android:layout_width="fill_parent" 
     android:id="@+id/editText2" 
     android:layout_height="fill_parent"> 
     <requestFocus></requestFocus> 
    </EditText> 

</FrameLayout> 

在这种布局中,editText2将覆盖editText1

+0

请参考这个问题http://stackoverflow.com/questions/7519160/android-overlay-a-view-ontop-of-everything。 – Recomer 2016-03-30 12:01:12

1

我相信你应该使用FrameLayout,您可以添加一个对象在其他的前面。请阅读文档。

+0

'RelativeLayout'也可以用于此。 – mah 2013-03-15 11:24:18

+0

是的,但我觉得它更容易与框架布局,其相对布局也不是很难, – 2013-03-15 11:24:57

+0

是,但点击任何按钮或背景(父)布局中的任何东西,向上滑动儿童布局,像动画一样向上 – Subha 2013-03-15 11:35:23

0
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root_view" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 
     <!-- other actual layout stuff here --> 

     </LinearLayout> 

    <LinearLayout 
    android:id="@+id/overlay" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right" > 
    </LinearLayout> 

    </FrameLayout> 

现在你的LinearLayout下添加与android:id = "@+id/overlay" 任何视图将显示为与重力覆盖=右

希望这会帮助你