【发布时间】:2013-08-18 13:26:02
【问题描述】:
我正在为 Android 开发,但遇到了问题。当我使用ViewGroup 的addView 方法添加ViewGroup 对象时,它不会在屏幕上显示任何内容。
谁能帮帮我?
RelativeLayout fullLayout=new RelativeLayout(this);
RelativeLayout top=new RelativeLayout(this);
TextView phoneNumber=new TextView(context);
phoneNumber.setText("137928833");
RelativeLayout.LayoutParams phoneParams=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
phoneParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); phoneParams.leftMargin=130; phoneParams.topMargin=120;
top.addView(phoneNumber,phoneParams);
fullLayout.addView(top,0);
我使用 setContentView(fullLayouot),它不起作用。
【问题讨论】:
-
请显示一些代码。你想做什么,你在哪里卡住了?
-
RelativeLayout fullLayout=new RelativeLayout(this);相对布局顶部=新的相对布局(这个); TextView phoneNumber=new TextView(context); phoneNumber.setText("137928833"); RelativeLayout.LayoutParams phoneParams=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); phoneParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); phoneParams.leftMargin=130; phoneParams.topMargin=120; top.addView(phoneNumber,phoneParams); fullLayout.addView(top,0);我使用 setContentView(fullLayouot),它不起作用。
-
@xiaoxiaoniao:为什么不把上面的代码(注释)保留在你的问题本身,让大家看清楚你的问题