我们要将一个张图片显示在屏幕上,首先需要创建一个显示图片的对象,在Android中,这个对象是ImageView对象,然后通过setImageResources 方法来设置要显示的图片资源索引。当然,还可以对图片执行一些其它的操作,比如设置它的Alpha值等。这里通过一个示例来给大家演示,我们另起一个线程来改变图片的Alpha值。如果大家对线程的交互不熟悉 那推荐大家看这篇文章了 写的很全面了。http://byandby.iteye.com/blog/825071 。我们先看看运行效果吧。
Activity01类
布局文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/TextView01"
android:layout_below="@id/ImageView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
源码大家可以在附件下载。http://dl.iteye.com/topics/download/014ccad1-d6e4-35c1-bc48-786012824693