Xamarin.Android - 为什么我的水平可绘制按钮之间没有空格?

时间:2017-02-16 17:05:57

标签: android android-layout xamarin.android

我的按钮最终看起来像这样: like this

这是4个切换按钮(好,3个半),第2个被选中。我在drawable中设置填充,但由于某种原因填充被忽略,或者在文本的按钮边框上使用。如果我不使用drawable,默认的Android按钮看起来很好,它们之间没有空格。

布局示例:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:minWidth="25px"
    android:minHeight="25px">
    <ToggleButton
        android:text="@string/btn_resp_tmp"
        android:id="@+id/resp1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/CustomSelector"
        android:enabled="true" />
    <ToggleButton
    (...)

我的drawable样本:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  <item android:state_checked="true">
    <shape >
        <solid
            android:color="#FF9800" />
        <stroke
            android:width="1dp"
            android:color="#E0E0E0" />
        <corners
            android:radius="4dp" />
        <padding
            android:left="10dp"
            android:right="10dp"
            android:top="10dp"
            android:bottom="10dp" />
    </shape>
  </item>
  <item >
    <shape >
        <solid
            android:color="#E0E0E0" />
        <stroke
            android:width="1dp"
            android:color="#E0E0E0" />
        <corners
            android:radius="4dp" />
        <padding
            android:left="10dp"
            android:right="10dp"
            android:top="10dp"
            android:bottom="10dp"  />
    </shape>
  </item>
</selector>

任何帮助都会非常感激,因为我的google-fu严重让我失败了。

1 个答案:

答案 0 :(得分:1)

将形状填充设置为以下代码时:

<padding
      android:left="10dp"
      android:right="10dp"
      android:top="10dp"
      android:bottom="10dp" />

这意味着红线为10dp。

enter image description here

但是in选择器无法定义形状边距。因此,作为工作区,您可以设置切换按钮边距:

<ToggleButton
        ......
        android:layout_marginRight="5dp"
         ..... />