我一直在瞎搞这个几天,希望这里有人能伸出援助之手。

我有一个简单的两列布局中,左侧是带有按钮的导航栏,右侧是内容面板。当用户点击按钮(比方说,第三个向下)之一,我想有一个浮动视图对准这个按钮的右侧,但漂浮在内容窗格顶部。这里有一个图片,说明我的意思: “布局”

一切我已经试过猛推导航栏里面或内容面板内浮动菜单,这不是我想要的。有任何想法吗?这里的基本上是我到目前为止有:

<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里,你的“静止”视图作为第一个子元素,并作为第二个孩子的浮动菜单。

显影剂文档有一个很好的概述布局类型,它可以帮助您开始。

其他提示

RelativeLayout是你想要的。结果 FrameLayout必须只有一个孩子,并且因此,通常仅用于一个占位符,其中其它布局来以后(如活动的主框架)。结果 AbsoluteLayout已过时,并且不应当被使用。

RelativeLayout允许视图重叠,并允许做,好看多了,任何你想要的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top