我一直插科打诨与此几天了,希望这里有人能借给我一只手。
我有一个简单的两列布局中,左侧是带有按钮的导航栏,右边是一个内容面板。当用户点击该按钮(例如,第三个向下)之一,我想有一个浮动的观点一致,以这个按钮的权利,而是浮在内容窗格顶部。这里有一个图片来说明我的意思:
一切我已经试过塞到里面的导航栏或内容面板内的浮动菜单,这不是我想要的。有任何想法吗?这里基本上是我到目前为止有:
< RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=横向
>
<的LinearLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
机器人:layout_alignParentLeft =真
机器人:ID =@ + ID / navigation_bar
>
<的FrameLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =0.14
>
<的ImageButton
机器人:ID =@ + ID / button1_btn
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/图标
机器人:layout_gravity =中心
/>
< /的FrameLayout>
<的FrameLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =0.14
>
<的ImageButton
机器人:ID =@ + ID / button2_btn
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/图标
机器人:layout_gravity =中心
/>
< /的FrameLayout>
< / LinearLayout中>
<的FrameLayout
机器人:ID =@ + ID /内容
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =0.14
机器人:layout_toRightOf =@ ID / navigation_bar
>
< /的FrameLayout>
< / RelativeLayout的>
解决方案
一个的FrameLayout可以让你有一个观点重叠的另一种观点。我不知道它是有道理让他们只有一个孩子看,因为你在你的例子。尝试具有的FrameLayout的最高水平,你的静态的观点作为第一个子元素,而浮动菜单的第二个孩子。
借助开发文档有一个很好的概述的布局类型,它可以帮助您开始。
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>
解决方案
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.