2012-08-29 54 views
0

我有一個使用gridview實現的菜單,其中每個單元由帶有可繪製圖標的TextView組成。結果是屏幕上充滿了每個圖標下帶有說明的圖標。大多數的圖標從資源加載這樣的:將TextView繪製爲相同大小

byte[] imageAsBytes = org.kobjects.base64.Base64.decode(base64BitmapString); 
Bitmap bmp = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length); 
Drawable img = new BitmapDrawable(parent.getResources(), bmp); 
textView.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null); 

Drawable img = getResources().getDrawable(R.drawable.people); 
textView.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null); 

爲了個性化菜單,少數的圖標會被存儲在數據庫中,並加載這樣的位圖加載

我遇到的問題是從數據庫加載的資源並不總是顯示與從資源加載的圖標相同的大小。在某些設備上,它們尺寸相同,但在其他設備上較小。

什麼是正確的方式來使所有的繪圖縮放到相同的大小?

所有圖像都是100x100 png文件。 Android SDK目標版本爲8及以上。

我編輯這包括對電網的XML與網格單元:

網格單元:

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/label" 
    style="@style/ButtonGridCell" 
    android:layout_centerHorizontal="true" 
    android:drawablePadding="4dp" 
    android:gravity="center" > 
</TextView> 

頁面與網:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/PageLayout" > 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 
     <ImageView 
      android:id="@+id/homelogo" 
      style="@style/HomeLogo" /> 
     <GridView 
      android:id="@+id/button_grid" 
      style="@style/ButtonGrid" 
      android:layout_below="@id/homelogo" > 
     </GridView> 
    </RelativeLayout> 
</RelativeLayout> 

樣式:

<style name="ButtonGridBase"> 
    <item name="android:layout_width">fill_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_centerHorizontal">true</item> 
    <item name="android:horizontalSpacing">15dp</item> 
    <item name="android:verticalSpacing">18dp</item> 
    <item name="android:gravity">center</item> 
    <item name="android:stretchMode">columnWidth</item> 
    <item name="android:layout_margin">8dp</item> 
    <item name="android:fadeScrollbars">false</item> 
</style> 
<style name="ButtonGrid" parent="@ButtonGridBase"> 
    <item name="android:columnWidth">100dp</item> 
    <item name="android:numColumns">auto_fit</item> 
</style> 
+0

而你從可繪製文件夾中得到的那些文件夾,他們在哪個文件夾? – iTurki

+0

資源從可繪製文件夾加載。我沒有爲hdpi,mdpi和ldpi製作不同版本的圖像。 –

回答

相關問題