2015-02-08 160 views

回答

0

我不确定这是否是您正在寻找的确切答案,但我使用AppCompat(ActionBarActivity)库构建了一个导航抽屉。我还添加了诸如spinners(下拉列表)之类的东西到导航抽屉XML中,用于不同的屏幕。

注意:在这个例子中,我实际上是以编程方式将条目添加到XML中,但XML是抽屉的框架。我基本上做了一个垂直的线性布局,滚动链接列表编号为externalLinks

声明:纯化材料设计人员会注意到,我的导航抽屉在动作栏下方,但我喜欢提供并且不想掩盖的小汉堡包 - >箭头图标。区别在于actionBarSize的layout_MarginTop。

希望这会有所帮助!

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/drawerLayout" 
    android:background="@color/background" 
    > 

<!-- The main content view --> 
<LinearLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 
    <include layout="@layout/common_toolbar"/> 
    <ScrollView 
     android:id="@+id/login_scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 
<!-- There is a bunch of layout that I removed because it is just my app's screen and isn't part of the answer --> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
<!-- The navigation drawer --> 
<LinearLayout 
    android:layout_marginTop="?attr/actionBarSize" 
    android:id="@+id/drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="1dp" 
    android:background="@color/background" 
    android:orientation="vertical" 
    > 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="3dp" 
     android:background="@color/colorAccent" 
     /> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/background" 
     > 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      > 
      <TextView 
       android:id="@+id/navMoreTitle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/navExternal" 
       android:paddingTop="10dp" 
       android:paddingBottom="10dp" 
       android:paddingLeft="5dp" 
       android:paddingStart="5dp" 
       android:paddingRight="5dp" 
       android:paddingEnd="5dp" 
       android:minHeight="30dp" 
       android:gravity="center_vertical" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:background="@color/white" 
       /> 
      <LinearLayout 
       android:id="@+id/externalLinks" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:background="@color/background" 
       > 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
</android.support.v4.widget.DrawerLayout>