2013-09-16 40 views
0

我正在嘗試在這個問題中提出@lnamdar問(Drawer layout with fixed menu item)。我試圖對他們的解決方案做出更好的解釋。DrawerLayout上的底部項目

我想這一點:

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/black"> 

<!-- The main content view --> 
<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@android:color/transparent"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="@color/black" 
     android:text="This is the footer text"/> 

</RelativeLayout> 

<!-- The navigation drawer --> 
<ListView 
    android:id="@+id/left_drawer" 
    android:layout_width="300dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:background="@android:color/black"/> 

但是,這是導致列表視圖不顯示,當我切換打開/關閉,我看到的是腳註中的唯一的事情。 我試圖把listView和footer textView都放在RelativeLayout中,但是它隨着Drawer Layout類上使用的佈局參數的ClassCastException而崩潰。

感謝您的幫助!

回答

0

他們嘗試使用RelativeLayout,因爲它不在內容框架內,所以它給出了意想不到的結果。解釋非常簡單,因爲RelativeLayout是ListView的父級,它保存的菜單項我們將重力移動到它,而使用ListView具有相同的重力。 這裏是我做過什麼:

<ListView 
    android:id="@+id/left_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:background="#111" 
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="0dp" /> 

<TextView 

     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="?android:attr/activatedBackgroundIndicator" 
     android:gravity="center_vertical" 
     android:id="@+id/logout_item" 
     android:minHeight="?android:attr/listPreferredItemHeightSmall" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     android:text="@string/logout" 
     android:textAppearance="?android:attr/textAppearanceListItemSmall" 
     android:textColor="#fff" /> 

</FrameLayout> 
</RelativeLayout> 

不要忘記運行HierarchyViewer來擺脫不必要的ViewGroup。

+0

謝謝尼古拉,同時我得到了相同的結論,並能夠做到這一點。真的很感謝幫助! – cperes

相關問題