如何正确设计/风格的Andr​​oid导航抽屉抽屉、如何正确、风格、Andr

2023-09-05 05:50:58 作者:一念花开

林有麻烦找到如何正确设计标准导航抽屉的任何资源。我有以下的XML和我寻找各种方法来填充多个列表视图,更改文本的字体在列表视图等。

林试图设计类似于以下一些设计

林希望找到文件,指南,code,实例或引用除了我给的设计文档。林寻找关于如何正确地适应这个新的Andr​​oid设计模式不只是观念的,他们怎么可能看起来更实际的code。

NavDrawer

 < android.support.v4.widget.DrawerLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / drawer_layout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

<的FrameLayout
    机器人:ID =@ + ID / content_frame
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent/>

<的ListView
    机器人:ID =@ + ID / left_drawer
    机器人:layout_width =240dp
    机器人:layout_height =match_parent
    机器人:layout_gravity =开始
    机器人:choiceMode =singleChoice
    机器人:分隔=@机器人:彩色/透明
    机器人:dividerHeight =0dp
    机器人:后台=#FFFFFF/>
 < /android.support.v4.widget.DrawerLayout>
 

TextView的

 < TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / text1中
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:背景=机器人:ATTR / activatedBackgroundIndicator
机器人:重力=center_vertical
机器人:=了minHeight机器人:ATTR /列表preferredItemHeightSmall
机器人:以下属性来=16DP
机器人:paddingRight =16DP
机器人:文本=正在加载内容......
机器人:textAppearance =机器人:ATTR / textAppearanceListItem
机器人:文字颜色=#000000/>
 

解决方案

您可以使用任何的ViewGroup像一个LinearLayout中为你的抽屉。它不限于一个ListView和的FrameLayout。正因为如此,你可以风格你抽屉查看像一个活动,例如任何其他布局。你应该记住的唯一的事情是,NavigationDrawer可以只有两个孩子的。第一个是你的活动布局,第二是抽屉。随意他们的风格,只要你喜欢!

 < android.support.v4.widget.DrawerLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / drawer_layout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

<的FrameLayout
    机器人:ID =@ + ID / content_frame
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent/>

<! - 你的抽屉 - >
<的LinearLayout
    机器人:ID =@ + ID / drawer_view
    机器人:layout_width =240dp
    机器人:layout_height =match_parent
    机器人:方向=垂直
    机器人:layout_gravity =开始>

    <! - 使用你喜欢的任何视图 - >
    <的ListView
        机器人:ID =@ + ID / left_drawer
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:choiceMode =singleChoice
        机器人:分隔=@机器人:彩色/透明
        机器人:dividerHeight =0dp
        机器人:后台=#FFFFFF/>
< / LinearLayout中>
< /android.support.v4.widget.DrawerLayout>
 

Im having trouble find any resources on how to properly design a standard Navigation Drawer. I've got the below XML and am looking for ways to Populate multiple listviews, change font of text in listview etc.

Im trying to design similar to some of the following designs.

Im looking to find documents, Guides, code, examples or some direction besides referencing me to the Design doc . Im looking for more actual code on how to properly adapt this new Android Design pattern not just idea's of how they could look.

NavDrawer

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

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#ffffff"/>
 </android.support.v4.widget.DrawerLayout>

TextView

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Loading Content ..."
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="#000000" />

解决方案

You can use any ViewGroup like a LinearLayout for your Drawer. It is not limited to a ListView and a FrameLayout. Because of this you can style your Drawer View like any other layout of an Activity for example. The only thing you should keep in mind is that the NavigationDrawer can have only two childs. The first is your layout for the Activity and the second is the Drawer. Feel free to style them as you like!

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

<!-- YOUR DRAWER -->
<LinearLayout
    android:id="@+id/drawer_view"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_gravity="start">

    <!-- Use any Views you like -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#ffffff"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>