I want to do something like this:
View v1= new View(this);
v1.setBackgroundResource(R.drawable.pic1);
View v2 = new View(this);
v2.setBackgroundResource(R.drawable.pic2);
v1.addView(v2);
RelativeLayout.LayoutParams params;
rl = (RelativeLayout) findViewById(R.id.activity_main);
rl.addView(v1,params);
I know the code is wrong. It just show how I want to do.
Some websides said that viewGroup may help me to achieve this.
I had tried but never can v2 be shown on the screen.
Does someone can tell me how to achieve this?
Views cannot contain other Views. It simply doesn't work this way in Android.
If you want to place a View inside a different View, the containing View must extend the ViewGroup class.
There are several classes that can help you achieve this:
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With