2013-02-22 3 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)); 

ответ

0

Используйте пользовательские ListView и использовать таблицу-макет как пользовательские ListItem

Смежные вопросы