Android-动态添加线性布局,不包裹到后来动态添加的子对象的高度

Android-动态添加线性布局,不包裹到后来动态添加的子对象的高度,android,dynamic,android-linearlayout,Android,Dynamic,Android Linearlayout,我在一个垂直线性布局中添加了7个线性布局,在每一个布局中,我循环遍历一个光标,并为光标的每一行添加一个具有两个垂直文本视图的视图 除了线性布局没有包装到子视图的内容之外,其他一切都正常工作 我有一种感觉,这是因为我在添加子视图之前在layoutparams中设置了wrap_内容,但我在将linearlayouts layoutparams添加到主视图之前更新了它,它仍然没有包装 动态添加代码 while(c.moveToNext()) { if(!(c.getString(c.getCo

我在一个垂直线性布局中添加了7个线性布局,在每一个布局中,我循环遍历一个光标,并为光标的每一行添加一个具有两个垂直文本视图的视图

除了线性布局没有包装到子视图的内容之外,其他一切都正常工作

我有一种感觉,这是因为我在添加子视图之前在layoutparams中设置了wrap_内容,但我在将linearlayouts layoutparams添加到主视图之前更新了它,它仍然没有包装

动态添加代码

while(c.moveToNext()) {
    if(!(c.getString(c.getColumnIndex("date")).equals(startDate))) {
        if(thisLin != null) {
            LayoutParams thisLinParams = new LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            thisLin.setLayoutParams(thisLinParams);
            seven_wrapper.addView(thisLin);
        }
        thisLin = new LinearLayout(getActivity());

        // originally I was setting layoutparams here but I removed this
        // when I thought it wasn't wrapping properly as there were no child views
        // at this stage
        //LayoutParams thisLinParams = new LayoutParams(
        //  LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        //thisLin.setLayoutParams(thisLinParams);

        TextView t = new TextView(getActivity());
        t.setText(c.getString(c.getColumnIndex("date")));
        LayoutParams lparams = new LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        t.setLayoutParams(lparams);
        thisLin.addView(t);
    }

    sevenItem = inflater.inflate(R.layout.seven_item, container, false);

    TextView time = (TextView) sevenItem.findViewById(R.id.seven_item_time);
    TextView name = (TextView) sevenItem.findViewById(R.id.seven_item_name);
    time.setText(c.getString(c.getColumnIndex("time")));
    name.setText(c.getString(c.getColumnIndex("name")));
    thisLin.addView(sevenItem);

}
seven_wrapper.addView(thisLin);

c.close();
片段视图

<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
android:id="@+id/seven_day_rows_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</HorizontalScrollView>

子视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@+id/seven_item_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>

<TextView android:id="@+id/seven_item_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/seven_item_time"/>
</RelativeLayout>

我是个白痴

我的子视图被包装到父视图,父视图被包装到子视图,因此它仍然保持原始大小

将子对象更改为在高度上包裹内容,这一切都起到了作用