2012-11-08 67 views
1

由於我想在不提供特殊「HD」版本的情況下支持平板電腦和智能手機,因此需要根據用戶設備的分辨率來縮放圖像。這是ImageView的來源,看起來對三星Galaxy Nexus的好:中心繪圖和刻度高度

<ImageView 
         android:id="@+id/character" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentBottom="true" 
         android:layout_centerHorizontal="true" 
         android:background="@android:color/transparent" 
         android:scaleType="centerCrop" 
         android:src="@drawable/ma_un1_001" /> 

enter image description here

但是,這將削減在圖像上的Nexus 7 enter image description here

當我改變的寬度和高度到:

<ImageView 
       android:id="@+id/character" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_alignParentBottom="true" 
       android:background="@android:color/transparent" 
       android:scaleType="centerCrop" 
       android:src="@drawable/ma_un1_001" /> 

不幸的是,這使圖像縮小比例: enter image description here

改變XML來

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

仍然會削減圖像。

所以我改變了scaleType到FIT_START

<ImageView 
       android:id="@+id/character" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_alignParentBottom="true" 
       android:background="@android:color/transparent" 
       android:scaleType="fitStart" 
       android:src="@drawable/ma_un1_001" /> 

enter image description here

看起來我所有的設備很大,但是繪製的左對齊。 有什麼辦法可以集中它嗎?

+1

你嘗試過所有'scaleType'嗎? – Wenhui

+0

是的。例如,FitEnd會將可繪圖對齊到右側 – Goot

+0

如果scaleType都不適合您,我會說以編程方式縮放圖像到屏幕的高度和寬度。不難做到。 – Wenhui

回答

0

感謝文輝,我找到了解決方案。

<ImageView 
       android:id="@+id/character" 
       **android:layout_width="fill_parent" 
       android:layout_height="fill_parent"** 
       android:layout_alignParentBottom="true" 
       android:background="@android:color/transparent" 
       **android:scaleType="fitCenter"** 
       android:src="@drawable/ma_un1_001" /> 

將圖像縮放到每個屏幕大小並且不會切割任何東西。非常感謝你。