2016-07-11 43 views
1

我需要幫助。我一直在試圖操縱這一點,但似乎我無法完成這件事。我試圖將圖像放在抽屜佈局上。 我調用標題圖像佈局(header.xml)爲:標題圖片無法正確放置(DrawerLayout)

<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升)構型:

<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 : [email protected]" 
     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 : [email protected]" 
     android:drawableLeft="@drawable/email" 
     /> 
</LinearLayout> 

我把圖像切斷了。

enter image description here

+0

嘗試在標題的XML中添加'android:scaleType =「centerCrop」''''''' – mastrgamr

+0

您的活動使用什麼風格? – uguboz

+0

它似乎navview站在操作欄後面 – uguboz

回答

1

你的形象是不是能夠適應,因爲圖像尺寸的屏幕,您可以設置規模類型fitxy以這種方式將填補左空間和STRETCH時的圖像

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

output

+0

嗨,我剛剛添加了該行,但圖像仍然得到了很好的效果 –

+0

它適合屏幕? –

+0

你正在使用什麼尺寸的圖像 –