I am trying to click a photo using the camera, and then display it in imageView. Initially, the image looked extremely small, and did not fit in the imageView. However, after reading a couple of blogs, I made the following change to the code:
photo = android.provider.MediaStore.Images.Media.getBitmap(cr,Uri.fromFile(tempPhoto));
//image.setImageBitmap(photo);
Drawable drawable = new BitmapDrawable(getResources(), photo);
image.setBackground(drawable);
image.setScaleType(ScaleType.FIT_CENTER);
My Layout file is as shown:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<AutoCompleteTextView
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:background="@color/translucent_grey"
android:ems="10"
android:hint="@string/hint_location"
android:inputType="text"
android:textSize="14sp" >
<requestFocus />
</AutoCompleteTextView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="200dp" >
<ImageButton
android:id="@+id/snap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/image"
android:layout_alignParentRight="true"
android:layout_marginBottom="108dp"
android:layout_marginRight="160dp"
android:background="@color/white"
android:src="@drawable/camera" />
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:orientation="horizontal" />
</RelativeLayout>
<FrameLayout
android:id="@+id/datetime_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="2dp" />
<FrameLayout
android:id="@+id/eventDetails_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp" />
</LinearLayout>
</ScrollView>
After adding this, the image stretches too much, and looks quite elongated. I am aiming to fit the image on the screen width, and then have flexible image height so that the scale can be maintained (just the way fb modile displays portrait and landscape images fitting along the width of the screen)
Does anyone know how?