嗨所有我有这个代码,我试图从SD卡读取2个图像,我不知道如何暂停2张图像,我可以有时间看到他们每一个,我也不知道如何在显示2张图像后清除图像
这就是我想要的方式
load first iamge->wait for 5 sec->load sec image->wait for 5 sec clear the ImageView
谢谢.....
package com.paad.ReadfromSD;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class ReadfromSD extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String imageInSD = "/sdcard/Hanud/AD2.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView myImageView = (ImageView)findViewById(R.id.imageview1);
myImageView.setImageBitmap(bitmap);
String imageInSD2 = "/sdcard/Hanud/AD1.jpg";
Bitmap bitmap2 = BitmapFactory.decodeFile(imageInSD2);
ImageView myImageView1 = (ImageView)findViewById(R.id.imageview1);
myImageView1.setImageBitmap(bitmap2);
}
}
这是布局文件:
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:id="@+id/imageview1"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
/>
</LinearLayout>
感谢所有
答案 0 :(得分:0)
public class ImgLoadAct extends Activity {
/** Called when the activity is first created. */
Timer timer;
ImageView myImageView;
TextView titleText;
Drawable img1Drawable;
Drawable img2Drawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myImageView = (ImageView)findViewById(R.id.imageview1);
titleText=(TextView)findViewById(R.id.img_title);
img1Drawable=getResources().getDrawable(R.drawable.android_logo);
img2Drawable=getResources().getDrawable(R.drawable.apple_logo);
//Load Img1 android_logo
myImageView.setImageDrawable(img1Drawable);
titleText.setText("Img2 android_logo.png loaded");
timer=new Timer();
//delay amount of time(5s here) in milliseconds before first execution.
timer.schedule(loadImg2, 5000);
}
TimerTask loadImg2 = new TimerTask(){
@Override
//Load Img2
public void run() {
runOnUiThread(new Runnable(){
public void run() {
titleText.setText("Img2 apple_logo.png loaded");
myImageView.setImageDrawable(img2Drawable);
timer.cancel();
timer=new Timer();
timer.schedule(clearImg, 5000);
}
});
}
};
TimerTask clearImg = new TimerTask(){
@Override
public void run() {
// TODO Auto-generated method stub
runOnUiThread(new Runnable(){
public void run() {
timer.cancel();
titleText.setText("Img cleared");
myImageView.setImageDrawable(null);
}
});
}
} ;
}