如果ScrollView是父级,则它不会将TableLayout显示为RelativeLayout(Android)

时间:2015-03-12 00:19:25

标签: android relativelayout android-tablelayout android-scrollview

我有这个xml文件:

 <ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RelativeLayout android:id="@+id/conteiner_2"
            android:layout_width="500px"
            android:layout_height="500px"
            android:background="@drawable/gradient_2">
        </RelativeLayout>
    </HorizontalScrollView>
 </ScrollView>

我正在尝试创建一个TableLayout如果我删除它出现的ScrollViews,但是当我在TableLayout显示之前让它出现时,我就会这样做。 这是我的代码:

TableLayout table = new TableLayout(this);
    RelativeLayout.LayoutParams paramsTable = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    TableLayout.LayoutParams paramsRow = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,0,1.0f);
    TableRow.LayoutParams paramsCol = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT,1.0f);
    for(int row = 0 ; row < rows ; row++){
        TableRow row = new TableRow(this);
        row.setLayoutParams(paramsRow);

        for(int col = 0 ; col < column ; col++){
            TextView text = new TextView(this);
            text.setLayoutParams(paramsCol);
            text.setText(row + "-" + col);
            row.addView(text);
        }
        table.addView(row);
    }

    tabla.setLayoutParams(paramsTable);
    conteiner.addView(table);

抱歉我的英语不好,我希望自己明白了。

&LT;&LT;&LT;编辑&gt;&gt;&gt; 我必须在RelativeLayout中放置另一个布局,它可以工作。

1 个答案:

答案 0 :(得分:0)

我必须在RelativeLayout内放置另一个布局,它可以正常工作。