我要创建从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);