Android 浮动视图(在其他视图之上) [英] Android floating view (over other views)
问题描述
这几天我一直在纠结这个,希望这里有人能帮我一把.
I've been messing around with this for a few days now, hopefully someone here can lend me a hand.
我有一个简单的两栏布局,左侧是带按钮的导航栏,右侧是内容面板.当用户点击其中一个按钮(比如第三个向下)时,我希望有一个浮动视图与该按钮的右侧对齐,但浮动在内容窗格的顶部.这是一张图片来说明我的意思:
I have a simple two-column layout, the left side is a navigation bar with buttons, the right side is a content panel. When the user taps one of the buttons (say, the third one down), I'd like to have a floating view aligned to the right of this button but floating on top of the content pane. Here's a picture to illustrate what I mean:
我尝试过的所有操作都将浮动菜单推到导航栏内或内容面板内,这不是我想要的.有任何想法吗?到目前为止,这基本上是我所拥有的:
Everything I've tried shoves the floating menu inside the navigation bar or inside the content panel, which is not what I want. Any ideas? Here's basically what I have so far:
<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 允许您让一个视图与另一个视图重叠.我不确定让它们只有一个子视图是否有意义,就像您在示例中所做的那样.尝试在最高级别使用 FrameLayout,并使用静态"布局.view 作为第一个子元素,浮动菜单作为第二个子元素.
A FrameLayout allows you to have a view overlapping another view. I'm not sure it makes sense to have them with only one child view, as you have in your example. Try having a FrameLayout at the highest level, with your "static" view as the first child element, and the floating menu as the second child.
开发人员文档对布局类型有很好的概述,它可能会帮助您入门.
The developer documents have a good overview the layout types, it might help you get started.
这篇关于Android 浮动视图(在其他视图之上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!