TableLayout在API 15上无法正常显示

时间:2017-04-09 16:32:25

标签: android android-layout

您好我有一个在API 21 +上显示效果很好的tablelayout但不幸的是,当我尝试在API 15上运行我的应用程序时,我将行空白并完全拉伸并且看不到任何信息,我尝试滚动但我无法看到桌子上的任何想法?谢谢你的帮助!

XML:

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

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true" >

<HorizontalScrollView
    android:id="@+id/hscrll1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/entries"
    android:stretchColumns="*">

    <TableRow android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/row_cell">
    </TableRow>

</TableLayout>
    </RelativeLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>

JAVA:

valuesTable.removeAllViews();

//add header
        TableRow tbrow0 = new TableRow(ctx);
        tbrow0.setLayoutParams(new LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT));
        TextView tv0 = new TextView(ctx);
        tv0.setText("Id");
        tv0.setTextSize(20);
        tv0.setTextColor(Color.WHITE);
        tv0.setPadding(10, 10, 10, 10);
        tbrow0.addView(tv0);
        TextView tv0 = new TextView(ctx);
        tv0.setText("name");
        tv0.setTextSize(20);
        tv0.setTextColor(Color.WHITE);
        tv0.setPadding(10, 10, 10, 10);
        tbrow0.addView(tv0);
        TextView tv0 = new TextView(ctx);
        tv0.setText("color");
        tv0.setTextSize(20);
        tv0.setTextColor(Color.WHITE);
        tv0.setPadding(10, 10, 10, 10);
        tbrow0.addView(tv0);


        valuesTable.addView(tbrow0);

        //Add row information

            TableRow tbrow = new TableRow(ctx);
            tbrow.setLayoutParams(new LayoutParams(
                    LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT));
            for(String value : row.getValues()){
                TextView t1v = new TextView(ctx);               
                t1v.setText(value);
                t1v.setTextSize(17);
                t1v.setTextColor(getResources().getColor(R.color.darkgray));
                t1v.setPadding(10, 10, 10, 10);
                t1v.setGravity(Gravity.CENTER);
                tbrow.addView(t1v);
            }

            valuesTable.addView(tbrow);

1 个答案:

答案 0 :(得分:0)

删除滚动视图中的相对布局是旧API的诀窍。