ImageView size and scale

Description

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   w  w  w.  j a  v a  2 s  .  c  o m
<?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>
ImageView size and scale




















Home »
  Android »
    Android UI »




UI Basics
Action Bar
Animation
Button
Canvas
CheckBox
Clock Date Picker
Dialog
EditText
Event
Fragment
Gesture
GridView
ImageView
Layout
ListView
Map
Menu
Model
OpenGL
ProgressBar
RadioButton
Spinner
Tab
TextView
Thread
Toast
Video
View
WebView