【问题标题】:Navigation drawer with linearlayout implementation which supports all versions of android带有线性布局实现的导航抽屉,支持所有版本的android
【发布时间】:2015-06-17 13:10:12
【问题描述】:

我正在制作一个 android 应用程序,我想实现如下所示的导航抽屉,即

  1. 导航抽屉应该像在 Playstore 中一样覆盖操作栏,
  2. 导航抽屉应该是线性布局(所以我需要添加页眉、列表视图、页脚之类的东西)
  3. 应该在所有版本中都一样>Android 4.0

我想像下图中的抽屉一样实现

https://imgur.com/GhflPDh

【问题讨论】:

  • 那么你的主要问题是什么?
  • 你的意思是android 1.6 API 4还是android 4.0 API 14?无论如何,您应该提供具体问题并展示您的努力,这不是一个为我编写代码网站。

标签: android android-layout android-fragments navigation navigation-drawer


【解决方案1】:

将此布局用于您的活动

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar"></include>

   <!-- Your Main Content-->

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:orientation="vertical">

<!-- Your Header-->

    <ListView
        android:id="@+id/nav_drawer_options_list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:scrollbars="vertical"></ListView>

  <!-- Your Footer-->

</LinearLayout>


</android.support.v4.widget.DrawerLayout>

还有你的工具栏布局,tool_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/action_bar_color"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

</android.support.v7.widget.Toolbar>

【讨论】:

  • 这是这个问题的一个很好的答案。请提供拒绝投票的理由。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-22
  • 2020-07-11
  • 2020-09-11
  • 1970-01-01
相关资源
最近更新 更多