Transparent circle with border

后端 未结 10 1426
南方客
南方客 2020-12-04 10:48

I am trying to create a circle with only a border using XML in android:




        
相关标签:
10条回答
  • 2020-12-04 11:27
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="oval" >
    
            <gradient
                android:endColor="@android:color/transparent"
                android:gradientRadius="20"
                android:startColor="@android:color/transparent" />
    
            <stroke
                android:width="1dp"
                android:color="#d9d9d9" />
    
            <size
                android:height="100dp"
                android:width="100dp" />
            </shape>
        </item>
    
        <item
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp">
            <shape android:shape="oval" >
    
                <gradient
                    android:endColor="@android:color/transparent"
                    android:gradientRadius="20"
                    android:startColor="@android:color/transparent" />
    
                <stroke
                    android:width="1dp"
                    android:color="#b3b3b3" />
    
                <size
                    android:height="100dp"
                    android:width="100dp" />
            </shape>
        </item>
    </layer-list>
    
    0 讨论(0)
  • 2020-12-04 11:29

    Hollow

    <?xml version="1.0" encoding="utf-8"?>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <stroke
                android:width="1dp"
                android:color="@color/indicator_unselected" />
        </shape>
    

    Full

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <corners android:radius="100dp" />
        <solid android:color="@android:color/white" />
    </shape>
    
    0 讨论(0)
  • 2020-12-04 11:30
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="oval" >
    
                <stroke
                    android:width="4dp"
                    android:color="@color/colorPrimaryDark" />
                <corners android:radius="0dp" />
            </shape>
        </item>
        <item
            android:top="1dp"
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp">
    
            <shape android:shape="oval">
                <solid android:color="@color/colorRed" />
                <size android:height="@dimen/_100sdp"
                    android:width="@dimen/_100sdp"></size>
            </shape>
    
        </item>
    
    </layer-list>
    
    0 讨论(0)
  • 2020-12-04 11:35

    If you set the color to #00000000, the result will be transparent. You would want to do it this way if you wanted to change it in the future of development. If you wanted it to be red and partially transparent for example, it would be #ff000088 The last two numbers are the opacity. I do it this way to make future changes easier.

    0 讨论(0)
  • 2020-12-04 11:41

    Try something like this

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:innerRadius="0dp"
        android:shape="ring"
        android:thicknessRatio="2"
        android:useLevel="false" >
        <solid android:color="@android:color/transparent" />
    
        <stroke
            android:width="2dp"
            android:color="@android:color/darker_gray" />
    </shape>
    

    Update: made android:thicknessRatio="2" to give full circle (using Nexus 5 - Lollipop)

    0 讨论(0)
  • 2020-12-04 11:43

    use this it will work

    <?xml version="1.0" encoding="utf-8"?>  
         <shape xmlns:android="http://schemas.android.com/apk/res/android"                                                                                                                                                     
       android:shape="oval" >
    
    <gradient
        android:centerX=".6"
        android:centerY=".40"
        android:endColor="@android:color/transparent"
        android:gradientRadius="20"
        android:startColor="@android:color/transparent"
        android:type="radial" />
    
    <stroke
        android:width="1dp"
        android:color="#FFFFFF" />
    
    <size
        android:height="100dp"
        android:width="100dp" />
    
    </shape>
    
    0 讨论(0)
提交回复
热议问题