添加ImageView的布局 [英] Add imageview to layout

查看:100
本文介绍了添加ImageView的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建从code图像视图,并添加到布局...但我不使用IN-code设置layout.I有RelativeLayout的XML和使用的setContentView(R.layout.activity_game);

如何布局添加ImageView的?


解决方案

  RelativeLayout的RL =(RelativeLayout的)findViewById(R.id.id_of_your_relative_layout_here);
ImageView的IV =新ImageView的(这一点)
iv.setImageResource(R.drawable.some_drawable_of_yours); //或iv.setImageDrawable(getResources()getDrawable(R.drawable.some_drawable_of_yours));
rl.addView(四);

I want to create image view from code and add to layout...But l don't use in-code setup layout.I have RelativeLayout in xml and use that setContentView(R.layout.activity_game); How add imageview to layout?

解决方案

RelativeLayout rl = (RelativeLayout)findViewById(R.id.id_of_your_relative_layout_here);
ImageView iv = new ImageView(this)
iv.setImageResource(R.drawable.some_drawable_of_yours); //or iv.setImageDrawable(getResources().getDrawable(R.drawable.some_drawable_of_yours));
rl.addView(iv);

这篇关于添加ImageView的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆