【问题标题】:How to create Overlay layout in android如何在android中创建覆盖布局
【发布时间】:2013-03-04 02:09:22
【问题描述】:

我如何创建像我在后台附加的布局一样的布局。当我单击任何布局或返回该布局时,从该布局中,覆盖布局应该带有任何表单字段按钮或文本......任何

提前致谢。

【问题讨论】:

  • 您想要交换布局的可见性或者您的最终目标是什么?
  • 我的意思是,在布局底部的Airtel text.Ff我触摸它,数字布局要向上。再次单击相同的数字布局需要向下隐藏。类似于 android 键盘显示(如果单击文本框,则 android 键盘将向上滑动相同的效果)

标签: android


【解决方案1】:

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

【讨论】:

  • RelativeLayout 也可以用于此。
  • 是的,但我发现框架布局更容易,但相对布局也不是很难
  • 是的,但是点击背景(父)布局中的任何按钮或任何东西以向上滑动子布局,例如动画向下向上
【解决方案2】:

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

【讨论】:

【解决方案3】:
    <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" 将显示为重力=右的叠加层

希望对你有所帮助

【讨论】:

    猜你喜欢
    • 2011-04-26
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    相关资源
    最近更新 更多