1

以前は、ファイル res\layout\main.xml がありました。

    <ScrollView
    android:id="@+id/SCROLLER_ID"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.98"
    android:fillViewport="true"
    android:scrollbars="vertical" >

<TextView
    android:id="@+id/showmsg"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:scrollbarStyle="insideOverlay"
    android:scrollbars="vertical"
    android:textColor="@color/textshowmsgcolor"
    android:textSize="10dp" />
</ScrollView>

TextView を動的に作成する必要があるため、res\layout\main.xml が作成されました。

    <ScrollView
    android:id="@+id/SCROLLER_ID"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.98"
    android:fillViewport="true"
    android:scrollbars="vertical" >

<LinearLayout
    android:id="@+id/linearLayout2"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
</LinearLayout>

</ScrollView>

これは私の MainActivity.java です:

    TextView tv = new TextView(this);
    tv.setBackgroundColor(Color.parseColor("#112222"));
    tv.setId(windows.size()+100);
    tv.setTextSize(10);
    tv.setTextColor(Color.parseColor("#FFFFFF"));
    tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    ((LinearLayout) linearLayout2).addView(tv);

ウィンドウは動的に作成されます。残念ながら、ウィンドウがテキストでいっぱいになると、スクロールは動きません。古い設定を Java コードに書き込む方法を教えてください。

4

2 に答える 2

0

LinearLayoutを水平にするつもりでしたか?おそらく、垂直のLinearLayoutを使用することをお勧めします。

<LinearLayout
android:id="@+id/linearLayout2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
于 2012-10-21T17:11:39.820 に答える
0
    tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
((LinearLayout) linearLayout2).addView(tv);

これは、テキストビューをlinearlayoutに追加しているように見えます。これは、いっぱいになってもスクロールしません。スクロールを機能させるには、テキストビューをスクロールビューに追加する必要があります。

これが私がそれをする方法です

<ScrollView
android:id="@+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.98"
android:fillViewport="true"
android:scrollbars="vertical" ></ScrollView>

次に、Javaクラスで。

// First declare the scrollview
scrollview = (ScrollView) findViewById(R.id.YOURSCROLLVIEWSID);
TextView tv = new TextView(this);
// Set textsize, color, etc here.
scrollview.addView(tv);

それをテストします。:)

于 2012-10-21T17:12:13.250 に答える