2011-04-14 69 views
2

我一直在搜索,擺弄和哭了幾個小時,但無法弄清楚如何將圖像放入ImageView並使圖像呈現未縮放,右對齊並具有超出ImageView左側的溢出被裁剪。ImageView與右對齊,裁剪,未縮放的內容

的ImageView的被定義爲這樣:

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/bleh" 
></ImageView> 

layout_width設置爲fill_parent伸展和收縮的ImageView以適應屏幕。

layout_height設置爲wrap_content,因爲ImageView將始終具有固定的高度,由圖像確定。

我還沒有定義layout_gravity="right",因爲我的理解是關於ImageView在其父項中的定位,在這種情況下,由於ImageView的寬度設置爲fill_parent,因此它沒有效果。

使用上述佈局代碼,圖像縮放以適應ImageView。我可以防止縮放的唯一方法是設置android:scaleType="center",這可以防止縮放,但不幸的是會使圖像居中。

Ay的想法?否則,我正在玩弄以下替代方法:

  • 子類ImageView並實現我自己的onDraw()方法。
  • 將全圖像大小的ImageView放入ScrollView並將滾動修復到最右側(並禁用任何指示它是滾動視圖)。

回答

4

取代滾動視圖 - 將圖像放入LinearLayout或RelativeLayout中。製作佈局的layout_width fill_parent和layout_height包裝內容。然後在ImageView上使用layout right和wrap_content作爲寬度和高度。

<LinerLayout android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
<ImageView android:layout_gravity="right" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/bleh"/> 
</LinearLayout> 
+0

謝謝!!極大喜歡! :D – voodoo98 2015-02-26 17:59:48

2

@harmanjd:你已經做了一些錯誤,這是正確的方式: (抱歉,我不能評論你的答案)

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right"> 

    <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/bleh"/> 
    /> 
</LinearLayout> 
+0

我希望TextView(用於名稱)和Imageview(用於圖像)在一行中,並且我希望TextView左algn和Imageview右對齊。你能給我一個建議嗎? – CSharp 2012-06-28 05:01:25

+1

對不起,我認爲這是不正確的方式來要求建議...此帖有另一個要求 – Ging3r 2012-07-02 13:16:14