Scrollview不适用于TableLayout

时间:2013-12-09 11:56:12

标签: android scrollview tablelayout

我无法通过代码添加ScrollView的{​​{1}}来TableLayout进行滚动。出于某种原因,如果我使用TableRows,这将水平滚动但不垂直(显然),而我需要垂直和水平。但是,使用带有水平和垂直滚动条的HorizontalScrollView都不会。

我在以下xml中定义了ScrollViewScrollView

TableLayout

然后我将tablerows添加到tablelayout,如下所示,

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/ScrollView1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:scrollbars="horizontal|vertical" >

 <TableLayout
    android:id="@+id/table_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
 </TableLayout>
</ScrollView>

table = (TableLayout) findViewById(R.id.table_id); for (int i = 0; i < 9; i++) { TextView headerRow = new TextView(getApplicationContext()); // set up the keyboard so it doesn't go fullscreen //firstEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); switch (i) { case 0: headerRow.setText("B/Sight"); break; case 1: headerRow.setText("Int/Sight"); break; case 2: headerRow.setText("F/Sight"); break; case 3: headerRow.setText("Rise"); break; case 4: headerRow.setText("Fall"); break; case 5: headerRow.setText("Reduced Level"); break; case 6: headerRow.setText("Lat"); break; case 7: headerRow.setText("Long"); break; case 8: headerRow.setText("Remark"); break; } setCellProperties(headerRow); firstRow.addView(headerRow); } table.addView(firstRow); 的位置,

setCellProperties()

然后,我使用与上面相同的过程添加更多行数据。我已尝试将此ScrollView包装在另一个布局中,如LinerLayout,如其他一些问题所示,但我无法破解它。值得一提的是,这将在Landscape not Portrait中观看。

2 个答案:

答案 0 :(得分:2)

试试:

    <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="220dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/linearLayout1"
    android:background="#000000" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/linearLayout1" >
        </TableLayout>
    </RelativeLayout>
</ScrollView>

答案 1 :(得分:2)

感谢输入Engr,但在搞砸了一些后,似乎解决了以下问题。

   <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:scrollbars="horizontal|vertical" >

         <ScrollView
             android:id="@+id/scrollview"
             android:layout_width="wrap_content"
             android:layout_height="match_parent" >

             <TableLayout
                 android:id="@+id/table_id"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content">
             </TableLayout>
         </ScrollView>
  </HorizontalScrollView>