【问题标题】:custom layout in navigation drawer导航抽屉中的自定义布局
【发布时间】:2014-06-06 02:43:03
【问题描述】:

我是android新手,我按照这个教程来创建导航抽屉here

我成功制作了导航抽屉,但我不知道如何使用按钮、textview 将框架布局更改为我的自定义布局....我的应用程序只显示菜单和空白框架布局,我该如何解决这个问题?

<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" >

    <FrameLayout
       android:id="@+id/content_frame"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:text="asdsadsad" />

    <ListView
       android:id="@+id/left_drawer"
       android:layout_width="240dp"
       android:layout_height="match_parent"
       android:layout_gravity="start"
       android:background="@color/purple_dark"
       android:choiceMode="singleChoice"
       android:divider="@android:color/darker_gray"
       android:dividerHeight="0.1dp" 
       android:listSelector="@drawable/ic_drawer"/>

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

【问题讨论】:

  • 听这个 xml 用于 DrawerLayout。那么你想在 DrawerLayout 中添加按钮等吗?如果是,则创建一个单独的 row.xml 文件,然后填充该 xml 并创建一个自定义适配器。之后,您可以获得按钮或文本视图,无论您想要什么。

标签: android xml navigation-drawer


【解决方案1】:

您可以在 LinearLayout 上使用 RelativeLayout 而不是 FrameLayout,您可以在其中构建整个布局

【讨论】:

    【解决方案2】:

    如果您需要添加其他布局,则需要将其添加到您的 closeDrawerdrawerOpen

    请参考我的回答here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-24
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2017-01-01
      • 2020-06-29
      相关资源
      最近更新 更多