2011-09-22 47 views
0

我想讓我的tablelayout至少嵌套在一個relativeview可滾動。 嘗試了幾個教程,但沒有任何工作。這裏是XML和我的Java代碼: 滾動tabellayout不適用於Android

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:background="@color/white" android:padding="10px" 
android:layout_width="fill_parent" android:layout_height="fill_parent"> 
<TextView android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:id="@+id/textView1" 
    android:paddingBottom="10dp" android:text="Mijn Rooster" 
    android:textSize="20sp" android:layout_alignParentTop="true" 
    android:layout_alignLeft="@+id/tablelayout"></TextView> 
<ScrollView android:id="@+id/ScrollView01" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"> 
    <TableLayout android:id="@+id/tablelayout" 
     android:layout_width= 
"fill_parent" android:layout_height="wrap_content" 
     android:stretchColumns="0" android:layout_below="@+id/textView1" 
     android:layout_above="@+id/btnsearch"> 

    </TableLayout> 
</ScrollView> 

<Button android:id="@+id/btnsearch" android:layout_width="wrap_content" 
    android:text="Zoek op Datum" android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"></Button> 
</RelativeLayout> 

這裏是Java代碼:

TableLayout tl = (TableLayout) findViewById(R.id.tablelayout); 

    if (date_selected == null) { 
     for (int i = 0; i < roostermap.size(); i++) { 

      TableRow trdaydatetime = new TableRow(this); 
      TableRow trinfo = new TableRow(this); 

      trdaydatetime.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 

      TableRow.LayoutParams rowSpanLayout = new TableRow.LayoutParams(
        TableRow.LayoutParams.FILL_PARENT, 
        TableRow.LayoutParams.WRAP_CONTENT); 
      rowSpanLayout.span = 3; 

      TextView txtDay = new TextView(this); 
      TextView txtTime = new TextView(this); 
      TextView txtResult = new TextView(this); 

      // Set Text 
      txtDay.setText(roostermap.get(i).getDay(
        roostermap.get(i).getRoster_date().getDay(), 
        roostermap.get(i).getRoster_date()) 
        + " " + df.format(roostermap.get(i).getRoster_date())); 
      txtTime.setText(dft.format(roostermap.get(i).getRoster_start()) 
        + " - " + dft.format(roostermap.get(i).getRoster_end())); 
      txtResult.setText(roostermap.get(i).getWorkplace_name()); 

      // Day&Date Layout 
      txtDay.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
      txtDay.setPadding(5, 5, 0, 0); 
      txtDay.setTextColor(Color.BLACK); 

      // Text Time layout 
      txtTime.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
      txtTime.setTextColor(Color.BLACK); 
      txtTime.setPadding(0, 5, 10, 0); 
      txtTime.setGravity(Gravity.RIGHT); 

      // Text Result layout 
      txtResult.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
      txtResult.setPadding(5, 0, 0, 5); 

      trdaydatetime.addView(txtDay); 
      trdaydatetime.setBackgroundResource(R.drawable.trup); 
      trdaydatetime.addView(txtTime); 
      trinfo.addView(txtResult, rowSpanLayout); 
      trinfo.setBackgroundResource(R.drawable.trdown); 

      tl.addView(trdaydatetime, new TableLayout.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
      tl.addView(trinfo, new TableLayout.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
     } 

回答

0

爲了使「滾動」工作,你需要的ScrollView內容到比ScrollView本身大。由於您已將android:layout_height的值設置爲wrap_content,因此ScrollView的高度與其內容的高度相匹配 - 這意味着不滾動。

修復ScrollViewandroid:layout_height值,方法是將其設置爲fill_parent(可能爲android:layout_weight)或像素值。

0

消除ScrollView。你不能合併兩個都可以滾動的視圖,特別是如果滾動方向相同。

如果內容大於TableView的高度,TableView本身會處理滾動。

+0

TableView或TableLayout? –

+0

TableLayout,sry我的錯:http://developer.android.com/reference/android/widget/TableLayout.html – banzai86

相關問題