Shape drawable not working?

五迷三道 提交于 2019-12-13 10:23:02

问题


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:thickness="3dp"
    android:innerRadius="34dp">

    <solid android:color="@color/colorAccent"/>

</shape>

I want to create ring but nothing appears.


回答1:


use this code,

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"
        android:left="4dp">
        <shape
            android:shape="oval">
            <solid android:color="#ff0000" />
        </shape>
    </item>
    <item>
        <shape
            android:shape="oval">
            <stroke android:width="2dp"
                android:color="#ff0000"/>
        </shape>
    </item>
</layer-list>

using ring shape

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadius="15dp"
    android:thickness="10dp"
    android:useLevel="false">
    <solid android:color="#ff0000" />

</shape>



回答2:


You can try like this for ring shape with fill transparent. set this drawable to your control.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
  <corners android:radius="10dip" /> 
  <stroke android:width="2dip" android:color="@color/white" /> 
  <size android:width="100dp" android:height="100dp" /> 
  <solid android:color="@android:color/transparent" /> 
  </shape>



回答3:


You can create ring from following code

 <shape xmlns:android="http://schemas.android.com/apk/res/android"  
        android:shape="oval">
      <corners android:radius="10dip" /> 
      <stroke android:width="2dip" android:color="#ffffff" /> 
      <size android:width="75dp" android:height="75dp" />  
      </shape>


来源:https://stackoverflow.com/questions/36003882/shape-drawable-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!