2013-06-27 4 views
1

У меня был динамически заполненный список рабочих файлов TextView. Но теперь я хочу превратить его в многоколоночный TableView. У меня есть динамическое создание строк и добавление их в макет, но ничего не отображается. Может кто-то указать, что я не вижу?Содержимое Android TableLayout, не показывающее

Отладчик отображает макет, содержащий строки, содержащие текстовые изображения, содержащие текст. Я пробовал делать вещи match_parent ширины и высоты и все еще не мог ничего показать.

Вот код.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/detailScroll" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<LinearLayout 
    android:id="@+id/detailLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/almost_black" 
    android:orientation="vertical" > 

    <TableLayout 
     android:id="@+id/detailTable" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/almost_black" 
     android:orientation="vertical" 
     android:stretchColumns="1" > 

     <TableRow 
      android:id="@+id/testRow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/testText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Testing" /> 
     </TableRow> 
    </TableLayout> 

    <Button 
     android:id="@+id/protocolButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginLeft="40sp" 
     android:layout_marginRight="40sp" 
     android:background="@drawable/protocol_button" 
     android:minHeight="40sp" 
     android:onClick="getProtocol" 
     android:padding="5sp" 
     android:text="@string/protocol_button_text" > 
    </Button> 
</LinearLayout> 
</ScrollView> 

ява

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
setContentView(R.layout.detail); 
layout = (TableLayout) this.findViewById(R.id.detailTable); 
    TableRow tr; 

    if (project.ProtocolNumber != null) 
    { 
     tr = BuildTableRow(res.getString(R.string.protocol_number_header), project.ProtocolNumber); 
     layout.addView(tr); 
    } 
private TextView BuildTextView(String string) 
{ 
    TextView tv = new TextView(this); 
    tv.setLayoutParams(lparams); 
    tv.setText(Html.fromHtml(string)); 
    tv.setTextColor(Color.BLACK); 
    tv.setPadding(5, 5, 5, 5); 

    return tv; 
}// BuiltTextView 

private TableRow BuildTableRow(String left, String right) 
{ 
    TableRow tr = new TableRow(this); 
    LayoutParams rowParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    tr.setLayoutParams(rowParams); 
    tr.setBackgroundColor(Color.RED); 
    tr.addView(BuildTextView(left)); 
    tr.addView(BuildTextView(right)); 
    return tr; 
} 

Спасибо.

ответ

1

Фокус в том, чтобы избавиться от LayoutParams