Android表格左侧大小超出屏幕

时间:2015-08-27 13:15:43

标签: android tablelayout tablerow screen-size

我正在创建一个在Android中显示数据的表格。该表以编程方式生成,表格在横向上正确显示:

在肖像上正在剪切第一列,但滚动视图正常工作,请参阅右侧的列:

这是xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/RelativeLayout0"
android:layout_height="match_parent"

android:paddingBottom="0dp" tools:context="com.dynamicTable">

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#3d455b"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true">

    <HorizontalScrollView
        android:id="@+id/hscrll1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="0dp"
        android:paddingRight="0dp">


        <RelativeLayout
            android:id="@+id/RelativeLayout1"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:layout_height="fill_parent"
            android:orientation="horizontal">

            <TableLayout
                android:id="@+id/table_main"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="0"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:layout_centerHorizontal="true">
            </TableLayout>
        </RelativeLayout>
    </HorizontalScrollView>
</ScrollView>

此处以编程方式生成表:

 public void init() {
    TableLayout stk = (TableLayout) findViewById(R.id.table_main);

    TableRow tbrow0 = new TableRow(this);

    TextView tv0 = new TextView(this);
    tv0.setText(" Sl.No ");
    tv0.setTextColor(Color.WHITE);
    tbrow0.addView(tv0);
    TextView tv1 = new TextView(this);
    tv1.setText(" Product ");
    tv1.setTextColor(Color.WHITE);
    tbrow0.addView(tv1);
    TextView tv2 = new TextView(this);
    tv2.setText(" Unit Price ");
    tv2.setTextColor(Color.WHITE);
    tbrow0.addView(tv2);
    TextView tv3 = new TextView(this);
    tv3.setText(" Stock Remaining ");
    tv3.setTextColor(Color.WHITE);
    tbrow0.addView(tv3);
    TextView tv4 = new TextView(this);
    tv4.setText(" Stock Remaining 2 ");
    tv4.setTextColor(Color.WHITE);
    tbrow0.addView(tv4);
    TextView tv5 = new TextView(this);
    tv5.setText(" Stock Remaining 3 ");
    tv5.setTextColor(Color.WHITE);
    tbrow0.addView(tv5);
    stk.addView(tbrow0);
    for (int i = 0; i < 40; i++) {
        TableRow tbrow = new TableRow(this);
        TextView t1v = new TextView(this);
        t1v.setText("" + i);
        t1v.setTextColor(Color.WHITE);
        t1v.setGravity(Gravity.CENTER);
        tbrow.addView(t1v);
        TextView t2v = new TextView(this);
        t2v.setText("Product " + i);
        t2v.setTextColor(Color.WHITE);
        t2v.setGravity(Gravity.CENTER);
        tbrow.addView(t2v);
        TextView t3v = new TextView(this);
        t3v.setText("Rs." + i);
        t3v.setTextColor(Color.WHITE);
        t3v.setGravity(Gravity.CENTER);
        tbrow.addView(t3v);
        TextView t4v = new TextView(this);
        t4v.setText("" + i * 15 / 32 * 10);
        t4v.setTextColor(Color.WHITE);
        t4v.setGravity(Gravity.CENTER);
        tbrow.addView(t4v);
        TextView t5v = new TextView(this);
        t5v.setText("" + i * 15 / 32 * 10);
        t5v.setTextColor(Color.WHITE);
        t5v.setGravity(Gravity.CENTER);
        tbrow.addView(t5v);
        TextView t6v = new TextView(this);
        t6v.setText("" + i * 15 / 32 * 10);
        t6v.setTextColor(Color.WHITE);
        t6v.setGravity(Gravity.CENTER);
        tbrow.addView(t6v);
        stk.addView(tbrow);
    }

}

任何想法如何解决?

0 个答案:

没有答案