【问题标题】:Why does the inner circle fill the outer circle?为什么内圈填满外圈?
【发布时间】:2016-12-04 23:21:08
【问题描述】:

我正在尝试在 Android 中使用 xml 在一个大光圈内制作一个小黑圈。两个圆圈都有颜色、大小和笔划。为什么小黑圈填充的是 50dp 而不是 28dp?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--big light circle-->
    <item>
        <shape android:shape="oval">
            <solid android:color="#EEEEEE" />

            <size
                android:width="50dp"
                android:height="50dp" />

            <stroke
                android:width="2dp"
                android:color="#404040" />
        </shape>
    </item>
    <!--small dark circle-->
    <item>
        <shape android:shape="oval">
            <solid android:color="#AEAEAE" />

            <size
                android:width="28dp"
                android:height="28dp" />

            <stroke
                android:width="1dp"
                android:color="#464646" />
        </shape>
    </item>
</layer-list>

drawable的用法:

   <RadioButton
        android:id="@+id/radioButtonPositive"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:button="@android:color/transparent"
        android:drawableTop="@drawable/ic_choice_background"
        android:gravity="center"
        android:onClick="onRadioButtonClicked"
        android:layout_marginRight="110dp"/>

xml 生成 但我希望它生成 (外圈大小相同,此截图显示不正确)

【问题讨论】:

  • 你在哪个版本的android上测试它?
  • 屏幕截图是它在 Android Studio 中 xml 文件的设计选项卡上显示的内容。它呈现 API 23。我尝试在 4.3、5.0 和 6.0 设备上运行它,结果都显示相同。
  • 奇怪.. 尝试在
  • 我不确定在项目级别应用填充是什么意思。当我执行“ 时也不会自动完成
  • 使用android:left等应用填充&lt;item android:left="10dp"

标签: android xml radio-button xml-drawable


【解决方案1】:

改为下面

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--big light circle-->
<item>
    <shape android:shape="oval">
        <solid android:color="#EEEEEE" />

        <size
            android:width="50dp"
            android:height="50dp" />

        <stroke
            android:width="2dp"
            android:color="#404040" />
    </shape>
</item>
<!--small dark circle-->
<item android:bottom="11dp"
    android:left="11dp"
    android:right="11dp"
    android:top="11dp">
    <shape android:shape="oval">
        <solid android:color="#AEAEAE" />

        <stroke
            android:width="1dp"
            android:color="#464646" />
    </shape>
</item>

【讨论】:

  • 这对我有用!但它不应该是 22dp,因为你在两边都这样做是 11dp。我建议你添加 标签。
  • 你能解释一下为什么 标签没有像我预期的那样工作吗?
  • 不确定原因。我遇到了同样的问题,只有上述解决方案有效。
猜你喜欢
  • 1970-01-01
  • 2018-09-29
  • 1970-01-01
  • 1970-01-01
  • 2015-07-07
  • 2014-11-14
  • 2021-12-31
  • 2020-10-31
  • 2016-03-27
相关资源
最近更新 更多