2016-06-07 135 views
0

我有一個佈局與根相對佈局和和ImageView裏面當我設置它的源圖像不適合裏面到圖像視圖離開頂部和底部填充是在預覽但不是在xml中定義。我想知道如何拉伸圖像以完全適合ImageView。圖像不拉伸imageView android

XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#fff"> 
    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/place_demo_2" 
     android:id="@+id/back_ground_place" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="400dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Manila Main" 
     android:id="@+id/visit_place_title" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="68dp" 
     android:textColor="#fff"/> 
</RelativeLayout> 

Preview

+0

集'機器人:scaleType =「fitXY」'的'ImageView' –

回答

1

您將要在您的XML文件中使用android:scaleType。有幾種選擇,你可能會想玩,直到你得到你正在尋找的確切產品,但是,如果你不關心長寬比,這聽起來像你可能想要使用android:scaleType =「fitXY」。

你可以在這裏找到更多的信息: https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

下面是其餘的選項:

ImageView.ScaleType = 「CENTER」

  • 中心在觀看圖片,但不執行縮放。

ImageView。ScaleType =「CENTER_CROP」

  • 縮放圖像均勻(保持圖像的縱橫比),以使圖像的兩個尺寸(寬度和高度)將等於 或大於視圖的對應尺寸更大的(負 填充)。

ImageView.ScaleType =「CENTER_INSIDE」

  • 縮放圖像均勻(保持圖像的縱橫比),以使圖像的兩個尺寸(寬度和高度)將等於 或小於視圖的相應維度(減去填充)。

ImageView.ScaleType = 「FIT_CENTER」

  • 量表使用CENTER圖像。

ImageView.ScaleType = 「FIT_END」

  • 量表使用END圖像。

ImageView.ScaleType = 「FIT_START」

  • 量表使用START的圖像。

ImageView.ScaleType = 「FIT_XY」

  • 量表使用填充圖像。

ImageView.ScaleType = 「基質」 繪製時使用圖像矩陣

  • 量表。
0

那是因爲你已經對準的ImageView於母公司的底部,但有在400dp底部的餘量。
長話短說,刪除 android:layout_alignParentBottom="true" android:layout_marginBottom="400dp"
如果您想要圖像填滿整個屏幕,還要設置layout_height to match_parent
P. S.另外fill_parent已棄用,所以請改用match_parent

+0

沒有我不希望它在整個屏幕上,但佈局的只是連接頂部 –

+0

行,沒問題只是刪除'機器人: layout_alignParentBottom = 「真」 機器人:layout_marginBottom = 「400dp」' –

+0

我這樣做,甚至試圖

2

使用代碼:

YourImageView.SetScaleType(ImageView.ScaleType.FIT_XY); 

使用XML:

android:scaleType="fitXY" 

也見下文快照其他選擇。 enter image description here

3

使用android:scaleType在scaleType here

2

要麼使的ImageView的寬度WRAP_CONTENT 或 你必須設置Android平臺ImageView

android:scaleType="fitXY" 

檢查其他可用的選項:的ImageView的scaleType到fitXY

2

添加至圖片查看attr android:scaleType="fitXY"