我正在尝试实现一个Android应用,需要将图像旋转不同的持续时间。下面是我的代码:
new Thread(new Runnable() {
@Override
public void run()
{
runOnUiThread(new Runnable() {
@Override
public void run()
{
while(true)
{
for(int i = 0; i < lstData.size(); i++)
{
String pathFile = JG.PathFiles + lstData.get(i);
File f = new File(pathFile);
if(f.exists())
{
String fileName = lstData.get(i);
String [] extens = fileName.split("\\.");
if(extens.length > 1)
{
Log.d("test ... .. . ", "" + pathFile);
vImage.setImageBitmap(GetImage(pathFile));
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
});
}
}).start();
public static Bitmap GetImage(String pathImage)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(pathImage, options);
return bitmap;
}
我有以下两个问题:
1。图片未显示。
2。在线程运行时移动屏幕被锁定(我希望在图像旋转时允许使用像打开SharedPreferene
这样的操作)。有没有其他解决方案?
答案 0 :(得分:0)
public class RotateThread implements Runnable {
private View view;
private double duration;
private static final float ROTATE_FROM = 0.0f;
private static final float ROTATE_TO = -10.0f * 90.0f;
public RotateThread(final View view, final double duration) {
this.view = view;
this.duration = duration;
}
@Override
public void run() {
RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);
r = new RotateAnimation(ROTATE_FROM, ROTATE_TO,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
r.setDuration((long) duration);
r.setRepeatCount(0);
try {
Thread.sleep(500);
this.view.startAnimation(r);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}