Reputation: 535
I have a ListView Item that uses a Drawable as a default icon and am allowing an override if an icon is specified. When I load the Bitmap for the specified icon and set it to the ImageView that holds the default Drawable item, the size of the specified icon is far smaller.
Both the Drawable and the specified Icon are 128px x 128px so I "assumed" that they'd both be the same size upon loading.
Here's a screenshot of the problem.
Here is the XML for the ListItem:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dip" >
<ImageView
android:id="@+id/events1_lv1_listitem_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:contentDescription="@string/content_description_default_text"
android:src="@drawable/calendar" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/events1_lv1_listitem_headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/content_description_default_text"
android:gravity="center_vertical"
android:textSize="16sp" />
<TextView
android:id="@+id/events1_lv1_listitem_summary"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:contentDescription="@string/content_description_default_text"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
And here is the snippet where I load the bitmap into the list item icon:
File headerImageFile = new File(src);
Bitmap image = BitmapFactory.decodeStream(new FileInputStream(headerImageFile));
events1_lv1_listitem_icon.setImageBitmap(image);
Any help would be most appreciated!
Upvotes: 1
Views: 196
Reputation: 4124
Couldn't see your screen shot.
If your icon is 128px * 128px, you can set the layout_width
and layout_height
to 128px, then set the scaleType
to fitXY
or centerCrop
. Like this:
<ImageView
android:id="@+id/events1_lv1_listitem_icon"
android:layout_width="128px"
android:layout_height="128px"
android:scaleType="fitXY"
android:layout_marginRight="6dip"
android:contentDescription="@string/content_description_default_text"
android:src="@drawable/calendar" />
As to the meaning of scaleType
, you can see this link.
Upvotes: 0
Reputation: 22537
Avoid wrap_content. Set your images size to dp, and set scaleType to "fitXY".
The following will do for you*
<ImageView
android:id="@+id/events1_lv1_listitem_icon"
android:layout_width="128dp"
android:layout_height="128dp"
android:scaleType="fitXY"
android:layout_marginRight="6dp"
android:contentDescription="@string/content_description_default_text"
android:src="@drawable/calendar" />
Upvotes: 1