Android UI How to - ImageView size and scale








The following XML not only specifies the source of the image file but also sets the maximum dimensions of the image on the screen and define what to do if the image is larger than our maximum size.

In this case, we tell the ImageView to center and scale the image so it fits inside the size we specified.

Example

/*from   ww w .j  a  v  a  2s  .  c  om*/
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/image4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxHeight="50dip"
        android:maxWidth="35dip"
        android:scaleType="centerInside"
        android:src="@drawable/ic_launcher" />
</LinearLayout>
null