标题图片无法正确放置(DrawerLayout)

时间:2016-07-11 16:54:18

标签: android android-layout navigation-drawer

我需要帮助。我一直试图操纵这个,但似乎我不能完成这件事。我正在尝试将图像放在抽屉布局上。 我正在调用标题图像布局( header.xml ):

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/drawerLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      <FrameLayout
         android:id="@+id/containerView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical"/>

      <android.support.design.widget.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         ....
         app:headerLayout="@layout/header" <!--THIS IS THE HEADER-->
        ...
   </android.support.v4.widget.DrawerLayout>

对于此( header.xm l)配置:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="match_parent">

   <ImageView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@drawable/background"
      android:layout_marginBottom="0dp"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" Twitter : @Someone important"
            android:drawableLeft="@drawable/twitter"
           android:layout_marginBottom="0dp"
           />
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text=" e-mail : someoneimportant@earth"
      android:drawableLeft="@drawable/email"
      />
</LinearLayout>

我得到了

enter image description here

并尝试降低图像布局高度:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="match_parent">

   <ImageView
      android:layout_width="match_parent"
      android:layout_height="140dp"
      android:src="@drawable/background"
      android:layout_marginBottom="0dp"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" Twitter : @Someone important"
            android:drawableLeft="@drawable/twitter"
           android:layout_marginBottom="0dp"
           />
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text=" e-mail : someoneimportant@earth"
      android:drawableLeft="@drawable/email"
      />
</LinearLayout>

我把图像剪掉了。

enter image description here

1 个答案:

答案 0 :(得分:1)

由于图像尺寸,您的图像无法适合屏幕,因此您可以将比例类型设置为fitxy,这样它将填充左侧空间并拉伸图像

<ImageView
    android:layout_width="match_parent"
    android:layout_height="140dp"
    android:src="@drawable/background"
    android:scaleType="fitXY"
    android:layout_marginBottom="0dp"/>

output