我有一个应用程序,其中我有一个 ImageView
在 ImageView
我想在 2 秒后从服务器显示
。我该怎么做。image
最佳答案
创建一个 Runnable
执行您想要的更改(我想它将更改 ImageView
的位图),并使用 Handler
及其延迟将它们发布到主线程循环postDelayed()
方法。
要使其成为一个循环,您可以让 runnable
自己发布。
更新日期:
这样你就可以在 Handler
中打开 Activity。
final View imageView = (ImageView) findViewById(R.id.imageView);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Intent intent = new Intent(LoActivity.this, StartActivity.class);
-- For getting image form ImageView and Pass to Another Activity code --
imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
intent.putExtras(extras);
-- In upper Bundle you have your bitmap Image --
LoActivity.this.startActivity(intent);
LoActivity.this.finish();
}
});
}
}, 2000);
并且在 AnotherActivity.java 中,您将以这种方式获得 bitmap
。
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
image.setImageBitmap(bmp );
希望对你有帮助
关于android - 如何在 2 秒后从服务器在 imageview 中更改图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38240207/