是否可以使用计时器或线程在特定时间内使用不同图像更新我的图像视图?
答案 0 :(得分:15)
ImageView image = (ImageView) findViewById(R.id.test_image);
image.setImageResource(R.drawable.xxx);
使用上面的代码将图像设置为图像视图,并使用可以在UI中更改内容的线程,基本上就是这样的事情
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
ImageView image = (ImageView) findViewById(R.id.test_image);
image.setImageResource(R.drawable.xxx);
}
}).start();
}
答案 1 :(得分:0)
嗨检查这篇文章是imageview在图像视图中显示图像的示例
http://www.androidpeople.com/android-gallery-imageview-example
这是在imageview中设置图像的主要部分
imgView.setImageResource(R.drawable.xxx);
答案 2 :(得分:0)
您只需设置图片URI:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri uri;
if (data != null) {
uri = data.getData();
iv030.setImageURI(uri);
Toast.makeText(getApplicationContext(),uri.toString(),Toast.LENGTH_SHORT).show();
}
}
}
答案 3 :(得分:0)
val button = findViewById<Button>(R.id.button)
val image = findViewById<ImageView>(R.id.test_image)
button.setOnClickListener{
Log.i("Info", "Button Pressed")
image.setImageResource(R.drawable.test_image2)
}
答案 4 :(得分:0)
尝试使用setImageResource()
方法来动态更改图像。添加可绘制图像参考作为更改图像的参数。
下面给出了示例代码,
package com.vsoft.imagechanger;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView ChangeImage;
Button ChangeButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ChangeButton = (Button)findViewById(R.id.button1);
ChangeImage = (ImageView)findViewById(R.id.imageView1);
ChangeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//ChangeImage.setImageResource(R.drawable.xxx);
ChangeImage.setImageResource(R.drawable.imageView2)
}
});
}
}