我正在使用线程(runOnUiThread)将 imageView 添加到 mainActivity。
我不知道我应该将什么导入构造函数!它需要上下文,我尝试过,MainActivity.this
但它不起作用!getApplicationContext()
getBaseContext()
public void addImageView(final int belowId,final int id){
runOnUiThread(new Runnable() {
@Override
public void run() {
RelativeLayout rSub= (RelativeLayout) findViewById(R.id.rSub);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW, belowId);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
ImageView iv = new ImageView(?????);
iv.setImageResource(R.drawable.ic_launcher);
iv.setId(id);
rSub.addView(iv, lp);
}
});
}
并称之为:
new Thread(new Runnable() {
@Override
public void run() {
addImageView(belowId, tempId);
}
}).start();
任何帮助表示赞赏!