Home > Enterprise >  'circle' is incompatible with attribute shape (attr) enum [line=2, oval=1, rectangle=0, ri
'circle' is incompatible with attribute shape (attr) enum [line=2, oval=1, rectangle=0, ri

Time:12-01

I am looking to have a circle in a Xamarin.Android project. I looked up some SO articles and they mentioned using android:shape="circle" which I did. I shows properly in the design preview, but I am unable to build/run the project anymore. I do not want an oval, I need a circle specifically. This is the error:

  • 'circle' is incompatible with attribute shape (attr) enum [line=2, oval=1, rectangle=0, ring=3]

axml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="circle">
    <solid android:color="#FFF44444"/>
    <size android:height="1dp" android:width="1dp"/>
    <corners android:radius="30dp"/>
    <padding android:left="10dp" android:top="10dp" android:right="30dp" android:bottom="10dp" />
</shape>

CodePudding user response:

There are only four options we can used for properties android:shape.

The options are:

  line, oval, rectangle, ring 

If you want to a circle, you can select oval for android:shape.

Please refer to the following code:

<?xml version="1.0" encoding="utf-8" ?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval">
      <solid android:color="#FFF44444"/>
      <size android:height="1dp" android:width="1dp"/>
      <corners android:radius="30dp"/>
      <padding android:left="10dp" android:top="10dp" android:right="30dp" android:bottom="10dp" />
</shape>

A simple usage:

  <ImageView
    android:background="@drawable/myshape"
    android:text="test"
    android:layout_width="60dp"
    android:layout_height="60dp"/>

Update

I am able to get the circle, but no text is showing in it.

If you want to add text to the circle, you can use TextView and set the background for it.

Please refer to the following code:

<TextView 
    android:padding="3dp"
    android:background="@drawable/myshape"
    android:gravity="center"
    android:text="1"
    android:textSize="16sp"
    android:textColor="@android:color/white"
    android:layout_width="30dp"
    android:layout_height="30dp"/>
  • Related