2014-02-14 167 views
0

我有動態尺寸的圖像和具有統計高度的ImageView。 我試圖像這樣在我的imageView中綁定我的圖像。圖像水平中心圖像無法垂直對齊

ImageLink

Image 我的意思是水平填補ImageView,而不是垂直方向。這裏是我的代碼

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="280dp"> 
    <ImageView 
     android:id="@+id/exploreImage" 
     android:src="@drawable/beard1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</RelativeLayout> 

但現在ScaleType存在ImageView,允許這種方式進行綁定。

你有什麼想法如何做到這一點?

+1

圖片未找到 –

+2

圖片男人在哪裏? –

+1

您有足夠的信譽在問題中上傳圖片。請這樣做。 – user3301551

回答

0

將其放在scrollview內,改變你的imageview代碼如下:

<ImageView 
    android:id="@+id/exploreImage" 
    android:src="@drawable/beard1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
/> 
+0

那麼,它的一個非常好的主意,但它有一個填充scrollView Oo –

+0

頂部你可以創建自己的類,這個答案將幫助你很多:http://stackoverflow.com/a/4688335/1182971 – Dyna

+0

很高興,非常感謝你 我已經找到了解決方案,而沒有創建一個新的類。只需添加到您的答案 android:adjustViewBounds =「true」 我會接受它 –

0

以下XML產生非常相似輸出到你想要的東西。只需將所需高度設置爲低於圖像高度即可。

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="100dp" 
    android:scaleType="matrix" 
    android:src="@drawable/image_1" /> 

事實上,ScaleType.Matrix裝置使用圖像矩陣繪製時,你應該在以後的代碼提供縮放。當您設置scaleType="matrix"但在代碼中不提供矩陣時;那麼它不會縮放,但會從頂部開始裁剪圖像。

+0

但它也水平裁剪。我需要水平填充 –