2012-07-12 53 views
1

我有一個應用程序小部件,並且在其中我想在右下角顯示我應用程序圖標的縮小版。圖像的尺寸爲36x36,圖像在這些尺寸上看起來很好,但我希望圖像較小,大約爲18x18。但是,如果我在圖像編輯器中調整圖像大小或嘗試在代碼中縮放圖像,圖像會顯得失真。調整大小/縮放圖像會導致失真

這是正常的圖像看起來什麼:

enter image description here

這是縮放圖像:

enter image description here

這是ImageView代碼我使用:

<ImageView 
    android:id="@+id/widgetIcon" 
    android:src="@drawable/icon" 
    android:layout_width="18dp" 
    android:layout_height="18dp" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:scaleType="centerCrop" 
/> 

UPDATE:

其實我有不同的繪製文件夾中的形象,打破了這樣的:

繪製-LDPI:36X36

繪製-MDPI:48×48

繪製,華電國際:最高72x72

繪製-xdpi:96×96

我把該裝置屏幕截圖是Galaxy Nexus。

更新2:

這裏是整個佈局,該ImageView是,如果有差別。該小部件的底部有RelativeLayout,其中包含ImageView

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/widgetLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="@dimen/widget_margin"> 

    <RelativeLayout 
     android:id="@+id/widgetBgLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:paddingTop="10dp" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:background="@drawable/bg_widget" 
     > 

     <RelativeLayout 
      android:id="@+id/widgetStatusLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_alignParentBottom="true" 
      android:paddingTop="10dp" 
      > 
       <TextView 
        android:id="@+id/widgetStatus" 
        style="@style/WidgetStatus" 
        android:layout_centerVertical="true" 
        android:layout_alignParentLeft="true" 
       /> 

       <ImageView 
        android:id="@+id/widgetIcon" 
        android:src="@drawable/icon" 
        android:layout_width="18dp" 
        android:layout_height="18dp" 
        android:layout_alignParentRight="true" 
        android:layout_centerVertical="true" 
        android:scaleType="centerInside" 
        android:adjustViewBounds="true" 
       /> 

      </RelativeLayout> 
      <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:layout_above="@id/widgetStatusLayout"  
        android:layout_alignParentTop="true" 
      >  
        <TextView 
         android:id="@+id/widgetTitle" 
         style="@style/WidgetTitle" 
        /> 

        <TextView 
         android:id="@+id/widgetText" 
         style="@style/WidgetText" 
        /> 
      </LinearLayout> 
    </RelativeLayout> 

</FrameLayout> 

UPDATE 3

問題不與所述圖像的縮放,這是圖像上方的佈局重疊。不知道解決方案。

回答

0

您應該將圖像放入每個不同的可繪製文件夾(hdpi,ldpi,mdpi,xhdpi)。這應該有所幫助。另外,將android:scaleType更改爲fitCenter

+0

其實,我在我的OP中錯過了。我確實有不同的可繪製文件夾中的圖像,每個文件夾都有不同的尺寸。我會更新我的OP,因爲格式更好。但是,我嘗試使用'fitCenter',但得到了相同的結果。 – 2012-07-12 01:51:32

+0

嗯...你有沒有嘗試過'centerInside' for your scaleType? – BlackHatSamurai 2012-07-12 01:57:33

+0

試過了,'centerInside'沒有運氣。我再次更新了我的OP,以顯示「ImageView」所在的整個佈局,如果有幫助的話。 – 2012-07-12 02:25:36

相關問題