【发布时间】:2015-02-08 02:03:30
【问题描述】:
有人知道怎么做吗?!?
我已经在网上到处找了 3 天了,每个教程都只告诉你如何制作抽屉,但问题实际上是把东西作为每个选定项目的布局。
请帮忙!
【问题讨论】:
标签: android xml layout android-studio navigation
有人知道怎么做吗?!?
我已经在网上到处找了 3 天了,每个教程都只告诉你如何制作抽屉,但问题实际上是把东西作为每个选定项目的布局。
请帮忙!
【问题讨论】:
标签: android xml layout android-studio navigation
我不确定这是否是您正在寻找的确切答案,但我使用 AppCompat (ActionBarActivity) 库构建了一个导航抽屉。我还在导航抽屉 XML 中添加了诸如微调器(下拉列表)之类的内容,用于不同的屏幕。
注意:在此示例中,我实际上以编程方式将条目添加到 XML 中,但 XML 是抽屉的框架。我基本上做了一个垂直线性布局,id externalLinks 下的可滚动链接列表。
免责声明:纯粹的 Material Design 人员会注意到我的导航抽屉位于操作栏下方,但我喜欢提供的小汉堡 -> 箭头图标并且不想掩盖它。不同的是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>
【讨论】: