我已经搞砸了几天了,希望这里有人可以帮我一把。
我有一个简单的两列布局,左侧是带按钮的导航栏,右侧是内容面板。当用户点击其中一个按钮(例如,向下的第三个按钮)时,我希望有一个 float View 与此按钮的右侧对齐,但 float 在内容 Pane 的顶部。这是一张图片来说明我的意思:
我尝试过的所有操作都将 float 菜单推到导航栏或内容面板内,这不是我想要的。有任何想法吗?到目前为止,这基本上是我所拥有的:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:id="@+id/navigation_bar"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.14"
>
<ImageButton
android:id="@+id/button1_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon"
android:layout_gravity="center"
/>
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.14"
>
<ImageButton
android:id="@+id/button2_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon"
android:layout_gravity="center"
/>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.14"
android:layout_toRightOf="@id/navigation_bar"
>
</FrameLayout>
</RelativeLayout>
最佳答案
FrameLayout 允许您让一个 View 与另一个 View 重叠。我不确定让它们只有一个 subview 是否有意义,就像您在示例中所做的那样。尝试在最高级别使用 FrameLayout,将“静态” View 作为第一个子元素,将 float 菜单作为第二个子元素。
developer documents对布局类型有一个很好的概述,它可能会帮助您入门。
关于java - Android float View (在其他 View 之上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2268569/