0

这是xml代码:

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".DeleteActivity" >
<LinearLayout
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</LinearLayout>

这是java代码的一部分:

    LinearLayout linear_layout = (LinearLayout) findViewById(R.id.linear_layout);
    final TextView[] myTextViews = new TextView[count];
    do {
        myTextViews[pointer] = new TextView(this);
        myTextViews[pointer].setText(getResources().getString(R.string.data_dd) + data + "\n");
        linear_layout.addView(myTextViews[pointer]);
        pointer++;
    }while(c.moveToNext());

问题是只显示第一个文本视图。如果我使用相对布局而不是线性布局,它会显示所有文本视图,但彼此显示。我能怎么做?

提前谢谢!

4

1 回答 1

0
<LinearLayout
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
</LinearLayout>

我认为你应该改变 to 的LinearLayout方向verical。同样TextView,您正在动态创建的也没有LayoutParams

  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
         LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

  do {
       myTextViews[pointer] = new TextView(this);
       myTextViews[pointer].setText(getResources().getString(R.string.data_dd) + data + "\n");
       linear_layout.addView(myTextViews[pointer], layoutParams);
       pointer++;
  } while(c.moveToNext());
于 2013-04-24T08:51:03.233 回答