0

シェイプドローアブルを使用してボタンをスタイリングすると、ボタンが少し拡大しすぎたり、マージンが失われたりして、他のボタンとうまく整列しなくなります。理由は何でも:

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

これは私のレイアウトコードです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
 <TableLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:stretchColumns="*"
    android:weightSum="2" >
<TableRow
        android:id="@+id/tableRowMem"
        android:layout_weight="1" >

            <Button
                android:id="@+id/buttonA"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="A"/>

        <Button
            android:id="@+id/buttonB"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="B" />

    </TableRow>

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_weight="1" >

        <Button
            android:id="@+id/buttonC"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:text="C" />

        <Button
            android:id="@+id/buttonD"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:background="@drawable/buttonred"
            android:text="D" />
    </TableRow>
    </TableLayout>
    </LinearLayout>

そして、これは描画可能な形状です。

<?xml version="1.0" encoding="utf-8"?>
<selector android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<item>

    <shape>
         <gradient
    android:startColor="#FFFF0000"
    android:endColor="#80FF00FF"
    android:angle="45"/>

    </shape>
</item>
</selector>
4

5 に答える 5

1

各ボタンには、パディングまたはレイアウトマージンのdpがあるようです。

設定してみてください

android:padding=0

それがうまくいかない場合

android:layout_margin=0

これにより、デフォルトのボタンからマージンが削除されます。他の方法で解決したい場合は、カスタムボタンにマージンを追加してください

于 2013-02-23T06:47:57.737 に答える
1

下の図を見てください。デフォルトのボタンは9パッチ画像であるため、ボタンの後に常に余分なスペースがあります。これはボタンのキャプチャです。したがって、背景リソースを設定すると、空のスペースが画像で埋められます。したがって、ImageView代わりに使用することをお勧めします。それはimageviewで完全に動作します。パディングのような解決策があるかもしれませんが、状況によっては失敗します。ImageViewを使用して機能を実装できます。これがお役に立てば幸いです。

デフォルトボタン

于 2013-02-23T09:46:13.747 に答える
0

これはおそらく、他のドローアブルのキャンバスにパディングがある可能性があるためです。

キャンバスのパディング[xmlで設定したものではなく、デザイナーが画像自体で設定したもの]を確認し、新しいドローアブルと一致させて、同じかどうかを確認します。それらは同じである必要があります。

于 2013-02-23T06:55:08.727 に答える
0

以下のレイアウトで試してみてください。いくつかの関連する変更を行いました。

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/LinearLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
   <TableLayout
      android:layout_width="fill_parent"
      android:layout_height="0dip"
      android:layout_weight="1"
      android:stretchColumns="*"
      android:weightSum="2" >
  <TableRow
    android:id="@+id/tableRowMem"
    android:weightSum="1" >
        <Button
            android:id="@+id/buttonA"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:text="A"/>

    <Button
        android:id="@+id/buttonB"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:text="B" />

</TableRow>

<TableRow
    android:id="@+id/tableRow1"
    android:weightSum="1" >

    <Button
        android:id="@+id/buttonC"
        android:layout_width="0dp"
        android:layout_weight=".5"
        android:layout_height="fill_parent"
        android:text="C" />

    <Button
        android:id="@+id/buttonD"
        android:layout_width="0dp"
        android:layout_weight="0.5"
        android:layout_height="fill_parent"
        android:background="@drawable/buttonred"
        android:text="D" />
</TableRow>
</TableLayout>
</LinearLayout>
于 2013-02-23T07:02:58.337 に答える
0

ボタンにパディングを追加します。

android:padding="0dp"
于 2013-02-23T07:12:05.337 に答える