2017-03-02 21 views
1

我對Android的一個imageview的,我想橫向配合和所有設備停留在一個地方(無論大小)設置ImageView的,以適應任何設備的Android

<ImageView 
     android:id="@+id/Image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:foregroundGravity="bottom" 
     android:gravity="bottom|center_horizontal" 
     android:scaleType="center" 
     android:src="@drawable/image" /> 

圖像是1280px和我將它放置在屏幕的底部。但是,如果應用程序在平板電腦中打開,則圖像將移動到左側,而右側有一個巨大的空白區域。我試圖fitxy但圖像扭曲。我不想將圖像設置爲背景。

如何確保應用程序在平板電腦中打開時,圖像仍處於居中且右側或左側沒有空白空間?

+0

而不是android:src,嘗試使用android:background。 – Shekhar

+1

你試過android:layout_width =「match_parent」 android:layout_height =「match_parent」? –

回答

0

我認爲你可以在ImageViewLinearLayout中使用android:layout_weight="1"

<ImageView 
    android:id="@+id/Image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_alignParentBottom="true" 
    android:foregroundGravity="bottom" 
    android:gravity="bottom|center_horizontal" 
    android:scaleType="center" 
    android:src="@drawable/image" /> 

當然,如果您在佈局中有另一個視圖並且不希望被圖像覆蓋時,最好使用它。

0

你有一個ImageView,圖像視圖的來源是你的圖像;由於您的ImageView您有屬性

android:layout_width="wrap_content" 
android:layout_height="wrap_content" 

然後因爲它是包裹它你的ImageView的大小將是「平等」到圖像的尺寸。你要做的是指定圖像視圖的大小,而不管圖像的大小如何使用例如

android:layout_width="match_parent" 
相關問題