-1

テキストを動的に表示したいのですが、テキストを表示したいのですここに画像の説明を入力してくださいが、「表示>」ボタンをクリックすると、テキストがボックスに表示されます。

私が試したのは、2つのテキストビューを使用してそれを行うことです。

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="10dip"
                android:layout_marginLeft="10dip"
                android:layout_marginRight="10dip"
                android:layout_marginTop="2dip"
                android:text="some text"
                                    />

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"
                android:text="view >>"
                android:textSize="9sp" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="10dip"
                android:layout_marginLeft="10dip"
                android:layout_marginRight="10dip"
                android:layout_marginTop="2dip"
                android:text=" yes"
                                  android:textSize="11.0sp"
                android:visibility="invisible" />
        </RelativeLayout>

コード:

public void onClick(View v)
 {
        switch(v.getId())
        {
        case R.id.button1:
            tv1.setVisibility(View.VISIBLE);
            break;
        }
}

何が起こったのかというと、2番目のテキストビューが最初のテキストビューにテキストを表示しているということです。では、このようなテキストを表示することは可能ですか?そうでなければ、混乱したテキストビューを克服するために何をすべきですか?

4

1 に答える 1

0

結果は正常です。実際、RelativeLayoutを使用し、両方のテキストを同じ場所に配置しました(margin属性を使用)。したがって、相対レイアウトの代わりにLinearLayoutを使用するか、マージン値を変更するか、を使用して2番目のtextViewの位置を変更できますandroid:layout_below

于 2012-08-30T13:25:17.393 に答える