2012-01-04 39 views
3

在Android中,我注意到你可以在另一個頂部有一個固定的視圖。例如,當您打開瀏覽器並點擊搜索框時,會彈出一個鍵盤提示(在列表視圖的頂部)。但是,請注意,您仍然可以在列表視圖上上下滾動而不會丟失鍵盤。像:覆蓋視圖在Android中如何工作?

example showing keyboard overlaying the listview

會有人請解釋(最好是在另外一些示例代碼)是如何工作的?

我想要做的只是有一個自定義列表視圖總是有一個浮動導航欄的頂部視圖和列表視圖的底部(它實際上不是一個頁眉/頁腳的列表視圖,它更像是屏幕的頁眉/頁腳)。它與我剛剛描述的例子類似,用戶可以在導航欄以及導航欄「下面」的列表視圖中進行交互。

我對Android開發有些新鮮,所以請好好提供一點細節,如果您願意:)非常感謝提前!

回答

0

有很多方法可以做到這一點,我能想到的簡單使用線性佈局:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/header"> 
     //Here you add whatever you want in your "header" 
    </LinearLayout> 

    //create your listview 
    <ListView 
    android:id="@+id/content_list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000" 
    android:layout_marginRight="10dip" 
    android:layout_marginLeft="10dip" 
    android:layout_marginTop="10dip" 
    android:layout_marginBottom="10dip" 
    android:scrollbars="none" 
    android:paddingBottom="5dp" 
    /> 

    <LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/footer"> 
     //Here you add whatever you want in your "footer" 
    </LinearLayout> 

+0

感謝您的回覆。雖然特定的XML看起來可以在特定的屏幕上工作,但當用戶關閉鍵盤時它不起作用。我很抱歉,我的問題沒有真正指出這一點,我的錯。我想要實現的是實際上將兩個視圖重疊在一起,而不是將它們展平爲1視圖 - >原因是我需要在應用程序中的任何視圖之上創建一個特定的疊加導航標題視圖。如果我知道如何覆蓋2個視圖,我希望有一個簡單的方法來做到這一點 – 2012-10-12 02:27:44