我正在关注导航抽屉的android教程,但我无法在导航标题中显示图像
http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html/ 如何在导航抽屉中添加个人资料图片和电子邮件地址? 以下是导航标题
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="178dp"
android:background="#FF00CC"
android:weightSum="1">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">
<!-- Name-->
<TextView
android:id="@+id/usernameprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="kevin@gmail.com"
android:layout_marginLeft="16dp"
android:layout_marginTop="5dp"
android:textColor="@color/white"
android:textSize="16dp"
android:textStyle="normal"/>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="70dp"
android:src="@drawable/profile_sample"
android:layout_height="70dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="38dp"
android:id="@+id/circleView"/>
</RelativeLayout>
答案 0 :(得分:0)
导航抽屉header.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@mipmap/profile"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abc@gmai.com"
android:textSize="14sp"
android:textColor="#FFF"
android:textStyle="bold"
android:paddingBottom="4dp"
android:id="@+id/username"
android:layout_alignTop="@+id/profile_image"
android:layout_toRightOf="@+id/profile_image"
android:layout_toEndOf="@+id/profile_image"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp" />
</RelativeLayout>
导航抽屉所在的主屏幕
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/main_layout"
android:layout_centerVertical="true"
tools:ignore="ContentDescription"
android:layout_height="match_parent"
tools:context="com.uowd.sport.app.MainScreen">
<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">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:dividerHeight="0dp"
android:background="#004f71"
android:divider="@android:color/transparent"
android:choiceMode="singleChoice"
android:fitsSystemWindows="true">
<include
layout="@layout/header.xml"
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>