2013-02-22 58 views
0

我正在研究需要添加動態行的應用程序。他們面臨以下問題。Android ScrollView和TableLayout中的等列行

  1. 我有3列,需要他們每個人有相等的寬度。表列基於文本長度延伸,這使得應用程序變得混亂。

  2. 我已經添加了ScrollView,但無法正常工作。添加約五個多餘的行後,只有第一列可見。

佈局是2部分。桌面佈局出現在第二部分。 這是我的XML佈局。

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

<ImageButton 
    android:id="@+id/shw" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginBottom="24dp" 
    android:background="@null" 
    android:src="@drawable/shw" /> 

<ImageView 
    android:id="@+id/lbl" 
    android:layout_width="match_parent" 
    android:layout_height="75dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/moolbl" /> 

<EditText 
    android:id="@+id/tf" 
    android:layout_width="192dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/lbl" 
    android:layout_marginTop="15dp" 
    android:ems="10"/> 
<ImageButton 
    android:id="@+id/moob" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/lbl" 
    android:background="@null" 
    android:src="@drawable/moo" /> 



<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/shw" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/moob"> 
    <TableLayout 
     android:id="@+id/tbl" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tf" 
     android:layout_marginTop="51dp" 
     android:scrollbars="vertical" > 

     <TableRow 
      android:id="@+id/tblr" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" > 

      <TextView 
       android:id="@+id/word" 
       android:layout_weight="1" 
       android:text=" GUESS" 
       android:textStyle="bold" 
       android:typeface="sans" /> 

      <TextView 
       android:id="@+id/bull" 
       android:layout_weight="1" 
       android:text=" WORD" 
       android:textStyle="bold" 
       android:typeface="sans" /> 

      <TextView 
       android:id="@+id/cow" 
       android:layout_weight="1" 
       android:text=" MEAN" 
       android:textStyle="bold" 
       android:typeface="sans" /> 
     </TableRow> 
    </TableLayout> 
</ScrollView> 

在代碼部分(添加動態行)

TableRow tr = new TableRow(this); 
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, 
    LayoutParams.WRAP_CONTENT); 
lp.weight = 1; 
lp.gravity = Gravity.CENTER_HORIZONTAL; 
tr.setLayoutParams(lp); 
TextView tvLeft = new TextView(this); 
tvLeft.setLayoutParams(lp); 
tvLeft.setText(tft); 
TextView tvCenter = new TextView(this); 
tvCenter.setLayoutParams(lp); 
tvCenter.setText(word + ""); 
TextView tvRight = new TextView(this); 
tvRight.setLayoutParams(lp); 
tvRight.setText(mean + ""); 
tr.addView(tvLeft); 
tr.addView(tvCenter); 
tr.addView(tvRight); 

tbl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, 
    LayoutParams.WRAP_CONTENT)); 

回答