2010-05-14 63 views
1

我正在研究需要下載圖像並將其顯示在ImageView中的Android應用程序。位圖傳遞到主Java文件,並添加到圖像視圖這樣的:ImageView中的位圖從屏幕上被裁剪掉

comic = (ImageView) findViewById(R.id.comic); 
comic.setImageBitmap(c.getImageBitmap()); 

這工作,除了圖像的左側消失在屏幕上。 ImageView在ScrollView中,它保持正確的大小。這意味着ScrollView的右側有黑色空間,圖像被剪切到左側。

的XML的ImageView的是這樣的:

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <ImageView 
      android:id="@+id/comic" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:layout_gravity="center" 
      android:src="@drawable/xkcdlogo" /> 
    </HorizontalScrollView> 
</ScrollView> 

任何想法,爲什麼我的形象被切斷?

謝謝!

回答

5

你試過設置android:scaleType =「center」而不是android:layout_gravity =「center」?

這將使圖像在ImageView中居中而不縮放。

+0

謝謝!這解決了這個問題,但是現在,足夠小以適合屏幕的圖像在左上方對齊。有任何解決這個問題的方法嗎? – Computerish 2010-05-15 02:29:34

+1

使用'centerCrop'而不是'center'。所有選項都可以在這裏找到非常明確的解釋:[ImageView.ScaleType文檔](http://developer.android.com/reference/android/widget/ImageView.ScaleType.html)。警告:在我的Eclipse Graphical Layout可視化編輯器中,某些縮放類型無法正確顯示。使用Force並信任文檔,在真實設備和仿真器上運行。 – 2011-08-11 17:25:45

+1

有沒有辦法做到這一點,但能夠動態化圖像,而不會被裁剪? – richy 2012-06-29 03:17:09

3

機器人:scaleType =「centerCrop」

1

終於爲我工作的解決方案是設置內的ImageView具有固定的高度和寬度比最大圖像大,增添了不少的填充,然後設置android:scrollX和android:scrollY在xml中獲取放置在我需要它們的位置的圖像。這解決了在水平滾動中裁剪圖像的問題。