java - Android float View (在其他 View 之上)

标签 java android mobile android-layout

我已经搞砸了几天了,希望这里有人可以帮我一把。

我有一个简单的两列布局,左侧是带按钮的导航栏,右侧是内容面板。当用户点击其中一个按钮(例如,向下的第三个按钮)时,我希望有一个 float View 与此按钮的右侧对齐,但 float 在内容 Pane 的顶部。这是一张图片来说明我的意思: Layout

我尝试过的所有操作都将 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/

相关文章:

java - 在 WebLogic JMX : What is the status of threads that are not Idle, 占用或备用?

java - 性能/灵活性,例如类或扩展类

java - 在 Android 中重命名字符串

android - Unity3D 检查一个点是否在游戏对象内部

java - 为什么Tuckey UrlRewrite Filter在规则匹配后不调用chain.doFilter?

android - Howler JS 2.0-Cordova,Android,设备上未播放声音

android - RestSharp & MonoDroid : Error getting response stream (ReadDone2): ReceiveFailure

javascript - 单击时 JQuery 移动按钮样式更改

flutter - 在flutter中弹出屏幕后如何调用函数来更新值?

android - 如果无法选择模拟器或 Wi-Fi,您如何进行电话到服务器的开发?