I have a menu that is implemented using a gridview where each cell consists of a TextView with a drawable icon. The result is screen full of icons with a description under each icon. Most of the icons are loaded from resources like this:
Drawable img = getResources().getDrawable(R.drawable.people);
textView.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null);
In order to personalize the menu, a few of the icons are loaded from a bitmaps stored in a database and loaded like this:
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);
The problem that I am having is that the resources loaded from the database do not always show up the same size as the icons loaded from a resource. On some devices they are the same size but on other devices they are smaller.
What is the proper way to make all of the drawables scaled to be the same size?
All of the images are 100x100 png files. Android SDK target version is 8 and above.
I am editing this to include the xml for the grid and the grid cell:
Grid cell:
<?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>
Page with grid:
<?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>
Styles:
<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>