android 怎么再代码中设置imageview src
1个回答
推荐于2016-04-01 · 知道合伙人影视综艺行家
关注
展开全部
private ImageView imageView,imageView2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)super.findViewById(R.id.imageView);
imageView2=(ImageView)super.findViewById(R.id.imageView2);//找到你layout中对应的imageView
Drawable drawable=imageView.getBackground();//获取它的资源,返回类型是Drawable
//假设你想把imageView的图片设置到其他容器中,比如imageView2,
imageView2.setBackground(drawable);//imageView2就显示和imageView一样的图片了
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)super.findViewById(R.id.imageView);
imageView2=(ImageView)super.findViewById(R.id.imageView2);//找到你layout中对应的imageView
Drawable drawable=imageView.getBackground();//获取它的资源,返回类型是Drawable
//假设你想把imageView的图片设置到其他容器中,比如imageView2,
imageView2.setBackground(drawable);//imageView2就显示和imageView一样的图片了
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询