I’ve spent 3 hours trying to get this to work without success so heopfully someone here can help.
I have a FrameLayout that is being loaded via inflate from an XML file and in it I have the following layout:
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="@+id/element_image"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:scaleType="fitStart"
android:background="#888888" >
</ImageView>
<Button android:id="@+id/element_button"
style="@style/Button"
android:layout_gravity="right"
android:text="@string/element_button_label"
/>
</LinearLayout>
I have an image loaded from a BLOB which I want to display in this ImageView. In the GalleryAdaptor I load the image like this:
ImageView image = (ImageView) v.findViewById(R.id.element_image);
byte [] bitmapData = cursor.getBlob(4);
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
image.setImageBitmap(bitmap);
When I use android:scaleType=”fitStart” in the layout above the image is not scaled to the height or width of the ImageView but is about a third of it’s width (which I can see from the grey background I have given it) and is centered.
If I use android:scaleType=”fitXY” the image height is scaled but the width is not. Again the image is centered.
Can someone give me some pointers on:
- How to get the image to scale both height and width wise
- How to align the image top right
Answering my own question here – but looks like this was just an issue with the source image resolution. Android (2.2 at least) does not seem to want to scale these images up when fitStart or fitEnd is used – but when fitXY is used it does scale them.