开发者

android layout form activity

i am having an xml main.xml,which has few layouts

<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/mainl"
   android:tag="aa"
   android:orientation="vertical"
   android:layout_height="wrap_content"
   android:layout_width="fill_parent">

</LinearLayout>

Is it possible to add one more layout inside the LinearLayout from the Activity at Run time. I am able to create Layout in Activity(without using xml) ,but problem in add开发者_如何学运维ing this layout to xml at run time ,anyone has a solution


You won't add it to the XML at run-time, but you can add it to the layout, which I think is what you want to do.

parent.addView(child);


use the following code

LinearLayout parent,child;

child=new LinearLayout(this);

parent=(LinearLayout)findviewById(R.id.mainl);

LinearLayout.LayoutParams lp = new   LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,   LinearLayout.LayoutParams.FILL_PARENT);

parent.addView(child,lp);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜