在开发中实现对图像的缩放有很多方法,最简单的方法是改变ImageView控件的大小,我们只要将<ImageView>标签的android:scaleType的属性值设置为fitCenter,要是想实现图像的旋转可以使用android.graphics.Matirx类的setRotate来实现。
下面介绍,图片的旋转和缩放功能。
一、建立工程,如图
二、activity_main.xml中代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:>
android:layout_width="200dp"
android:layout_height="150dp"
android:src="@drawable/background"
android:scaleType="fitCenter"
>
</ImageView>
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="图像宽度:240 图像高度:160"
/>
<SeekBar
android:id="@+id/seekbar1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:max="240"
android:progress="120"
/>
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="0度"
/>
<SeekBar
android:id="@+id/seekbar2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:max="360"
/>
</LinearLayout>