简体   繁体   English

Android TableLayout内容未显示

[英]Android TableLayout content not showing

I had a dynamically populated list of TextViews working. 我有一个动态填充的TextViews列表。 But now I want to make it into a multi-column TableView. 但是现在我想使其成为一个多列的TableView。 I've got it dynamically creating the rows and adding them to the layout but nothing will display. 我可以动态创建行并将其添加到布局中,但是什么也不会显示。 Can someone point out what I can't see? 有人可以指出我看不到的东西吗?

Debugger shows the layout containing the rows containing the textviews containing the text. 调试器显示的布局包含包含文本视图的行,这些视图包含文本。 I've tried making things match_parent width and height and still couldn't get anything to show. 我已经尝试过使match_parent的宽度和高度匹配,但仍然无法显示任何内容。

Here is code. 这是代码。

<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>

java java的

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;
}

Thanks. 谢谢。

诀窍是摆脱LayoutParams

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM