android动态加载布局控件

//提供一个(布局)这个布局是一个xml,控件在xml中
View llHomeMember = inflater.inflate(R.layout.view_popuwindow_health_record_home_member, null);
//户主关系
tv_home_member_view = (TextView) llHomeMember.findViewById(R.id.tv_home_member_view);
//姓名
tv_name_view = (TextView) llHomeMember.findViewById(R.id.tv_name_view);
//性别
tv_sex_view = (TextView) llHomeMember.findViewById(R.id.tv_sex_view);
//出生日期
tv_birthday_view = (TextView) llHomeMember.findViewById(R.id.tv_birthday_view);
//身份证号
tv_id_card_view = (TextView) llHomeMember.findViewById(R.id.tv_id_card_view);
//把数据set进控件,
//加载到容器中
ll_home_member.addView(llHomeMember);


这是布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/tv_home_member_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/square_frame"
android:text="户主"
android:textSize="15sp"/>
<TextView
android:id="@+id/tv_name_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/square_frame"
android:layout_weight="1"
android:text="赵工"
android:textSize="15sp"/>
<TextView
android:id="@+id/tv_sex_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/square_frame"
android:layout_weight="0.5"
android:text="男"
android:textSize="15sp"/>
<TextView
android:id="@+id/tv_birthday_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/square_frame"
android:layout_weight="1"
android:text="1992-10-10"
android:textSize="15sp"/>
<TextView
android:id="@+id/tv_id_card_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/square_frame"
android:layout_weight="2"
android:text="500102199855547"
android:textSize="15sp"/>

</LinearLayout>
//这是容器
//1m2
<LinearLayout
android:orientation="vertical"
android:id="@+id/ll_home_member"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//1m2
</LinearLayout>

 

posted @ 2016-09-09 09:11  菜鸟也能成为架构师  阅读(1892)  评论(0编辑  收藏  举报