Android 定制导航绘图机

Android 定制导航绘图机,android,android-layout,Android,Android Layout,您好,我有这样的布局,我不知道如何添加静态标题与照片和文字 导航绞车。有什么例子吗?谢谢 像这个 在FrameLayout之后,第一个视图将被接受为导航抽屉,因此您可以在FrameLayout之后创建一个布局,然后将视图放在其中。这里有一个例子,它是非常基本的,但你会得到的要点 <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout

您好,我有这样的布局,我不知道如何添加静态标题与照片和文字 导航绞车。有什么例子吗?谢谢

像这个



在FrameLayout之后,第一个视图将被接受为导航抽屉,因此您可以在FrameLayout之后创建一个布局,然后将视图放在其中。这里有一个例子,它是非常基本的,但你会得到的要点

<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</FrameLayout>
<!-- The navigation drawer -->


<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_height="match_parent"
    android:layout_width="320dp"
    android:orientation="vertical"
    android:layout_gravity="start" >

    <RelativeLayout   
        android:id="@+id/NavDrawerInfo"      
        android:layout_width="320dp"
        android:background="@drawable/bg"
        android:layout_height="100dp">

        <ImageView android:src="@drawable/ic_launcher"
           android:id="@+id/userImage"
           android:layout_width="200dp"
           android:layout_marginRight="200dp"
           android:layout_height="100dp"/>
        <TextView 
             android:id="@+id/userName"
             android:layout_width="wrap_content"
             android:layout_height="100dp"
             android:layout_marginLeft="125dp"
             android:textSize="20sp"
            />
        <TextView 
             android:id="@+id/userImage"
             android:layout_width="wrap_content"
             android:layout_height="100dp"
             android:layout_marginTop="20dp"
             android:layout_marginLeft="125dp"
             android:textSize="20sp"
            />



 </RelativeLayout>
    <ExpandableListView android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:childDivider="@color/list_divider"
        android:groupIndicator="@drawable/group_indicator"
        android:dividerHeight="2dp"
        android:gravity="start" 
        android:background="#f1f1f1"/>


</LinearLayout>



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


它实际上并不像user665建议的那样简单。如果您直接使用Google提供的示例,则需要通过更改
DrawerLayout.isDrawerOpen
DrawerLayout.closeDrawer
来让
DrawerLayout
知道其内容。您的
列表视图
被包装在,否则您将抛出一个
ClassCastException
,因为
LayoutParams
不匹配

因此,要创建静态标头,可以执行以下操作:

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

    <LinearLayout
        android:id="@+id/drawer_content"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:orientation="vertical" >

        <ImageView
            android:id="@android:id/icon"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:contentDescription="@null"
            android:scaleType="centerCrop" />

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#111"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp" />
    </LinearLayout>

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

然后在使用上面列出的方法时参考
R.id.drawer\u内容

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

    <LinearLayout
        android:id="@+id/drawer_content"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:orientation="vertical" >

        <ImageView
            android:id="@android:id/icon"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:contentDescription="@null"
            android:scaleType="centerCrop" />

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#111"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp" />
    </LinearLayout>

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