0

TextView1、buttons1、buttons2 を水平方向に持っています。Button2 をクリックすると、Button1 は非表示になります。Button1 が非表示の場合、テキストビューの幅を広げて、button1 が非表示のときに作成されるスペースをカバーする必要があります。逆の場合も同様です。Textview の幅を動的に変更するにはどうすればよいですか。

注意: Textview tv.setWidth(pix) は機能していません。tv.getWidth() の値を見つけようとすると、常にゼロになります。

4

3 に答える 3

2

`

    <TextView
        android:layout_width="odp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/hello" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="odp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/hello"
        android:visibility="visible" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="odp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/hello" />
</LinearLayout>`you can use weight for three element and button1.setVisibility(View.GONE)
于 2012-09-02T06:22:44.787 に答える
2

INVISIBLE を使用する代わりに GONE を使用してみてください。見えなくても INVISIBLE を使用すると、やはりスペースが必要です。

于 2012-09-02T06:20:09.350 に答える
0

ウィジェットをラップしてRelativeLayoutからチェックします。目に見えない場合はtextview、上に重ねることができます。ウィジェットを水平または垂直に設定し、重なり合わないため、button使用している場合はこれを行うことはできません。LinearLayout

于 2012-09-02T06:42:13.667 に答える