简体   繁体   中英

Shape=ring in android not displaying

I am trying to display some text in a coloured circle, but it is not working properly. This is how I am rendering the text -

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="GO"
    android:background="@drawable/scancircle"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:textColor="#ffffff"
    android:textSize="18dp"
    android:padding="9dp"
    android:onClick="Go"
    />

And this is how scancircle.xml looks like -

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadius="93dp"
    android:thickness="1dp"
    android:useLevel="false"
    >
    <solid android:color="@color/primary" />
    <stroke
        android:width="2dp"
        android:color="@color/txtVwBackground"
        />

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

Even though the preview of scancircle shows the circle correctly, but there is no circle rendered behind the text. Can anyone tell why is this so?

Thanks in advance.

Well, actually you don't use circle , you use a ring , which has a hole in the middle. In your case this hole is of 93dp radius that makes it bigger than the TextView itself. Thus what you see behind the text is the hole part of the ring, which is transparent.

You may want to use oval shape for the "circle behind the text" effect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM