English 中文(简体)
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: Layout

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.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签