LinearLayout动态添加View

我LinearLayout动态添加View是实现像下面xml文件样式的布局
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#ff0"
        android:layout_weight="1"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#ff0"
        android:layout_weight="1"/>
</LinearLayout
我具体代码是这样写的
linearLayout = new LinearLayout(this);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            for (int i = 0; i < 2; j++) {
                view = View.inflate(LookLiveActivity.this, R.layout.item_vp_tv, null);
                //第一个参数代表横向填充父窗体题,第二个参数纵向为0dp,第三个参数为权重
                view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0,1));
                linearLayout.addView(view);
            }

posted @ 2016-07-06 13:31  我的网名  阅读(39)  评论(0)    收藏  举报