0

私の小さな問題を解決するのを手伝ってくれませんか?ボタンで作ったテーブルがあります。私のxmlファイルでは、ボタンにこのコードがあります

<Button
            android:id="@+id/b_0xa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_0xa" />

私のmain.classには、次の行があります。

b_0xb.setBackgroundResource(R.drawable.green);

クリックした後にボタンの背景を変更したいからです。正常に動作しますが、アプリケーションを実行すると、これが結果になります。

ここに画像の説明を入力してください

どうすれば修正できますか?width==heightのボタンが必要です。

どうもありがとう

4

2 に答える 2

0

テーブルレイアウトのすべてのボタンをグループ化しますこれはコードです

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/b_0xa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_0xa" />

        <Button
            android:id="@+id/b_0xb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_0xb" />

        <Button
            android:id="@+id/b_0xc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_0xc" />

        <Button
            android:id="@+id/b_0xd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_0xd" />

        <Button
            android:id="@+id/b_0xe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_0xe" />

        <Button
            android:id="@+id/b_0xf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_4xb" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/b_1xa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_1xa" />

        <Button
            android:id="@+id/b_1xb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_1xb" />

        <Button
            android:id="@+id/b_1xc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_1xc" />

        <Button
            android:id="@+id/b_1xd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_1xd" />

        <Button
            android:id="@+id/b_1xe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_1xe" />

        <Button
            android:id="@+id/b_1xf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="false"
            android:text="@string/b_4xb" />
    </TableRow>

于 2013-01-26T12:58:32.163 に答える
0

いくつかの方法がありますが、よくわかりませんが、以下のことを試してもらいたいです。

1) を削除し android:layout_weight="1"ます。

2) layout_width ="50dip" layout_Height ="50dip" のように xml で静的な高さと重量を設定します。

3) width パラメータをチェックして、Activity/onCreate で Height を設定します。view.getHeight(); のように ...

于 2013-01-26T13:13:02.313 に答える