TextView l_tv = new TextView(this);
l_tv.setText("you can do it");
l_tv.setTextColor(Color.WHITE);
l_tv.setBackgroundColor(Color.BLUE);
TextView l_tv2 = new TextView(this);
l_tv2.setText("hello");
l_tv2.setTextColor(Color.WHITE);
l_tv2.setBackgroundColor(Color.YELLOW);
FrameLayout l_fr = new FrameLayout(this);
RelativeLayout.LayoutParams l_layoutParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
l_layoutParams.leftMargin = 500;
l_layoutParams.topMargin = 100;
l_fr.setLayoutParams(l_layoutParams);
l_fr.addView(l_tv);
l_fr.addView(l_tv2);
((RelativeLayout) findViewById(R.id.layout1)).addView(l_fr);
((RelativeLayout) findViewById(R.id.layout1)).removeView(l_fr); (1)
((RelativeLayout) findViewById(R.id.layout1)).addView(l_tv); (2)
Keep an eye on (1). You removed l_fr. So was l_tv removed too? No. If you try to add l_tv like (2). You have a message like below.
The specified child already has a parent. You must call removeView() on the child's parent first.
'Android' 카테고리의 다른 글
Can't create handler inside thread that has not called Looper.prepare() (0) | 2013.08.05 |
---|---|
Fragment life cycle (0) | 2013.08.02 |
removeView function removes only direct child object. (0) | 2013.07.23 |
image resource size (0) | 2013.07.22 |
Making a transparent layout which is added to another layout (0) | 2013.07.08 |