Home > OS >  Android Studio - Oval shape view is appearing as a square
Android Studio - Oval shape view is appearing as a square

Time:12-02

I have a View set up with background as a oval shape.

<View
        android:id="@ id/circleView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="@drawable/bg_circle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

Here is my bg_circle.xml file

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    android:shape="oval">
    <solid android:color="@android:color/holo_green_light" />
    <size
        android:width="150dp"
        android:height="150dp" />
</shape>

I tried setting the width and height to the same values in both files, still doesn't work. My View is appearing as a square. How to fix this? Thanks.

CodePudding user response:

This is correct

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/holo_green_light" />
<size
    android:width="150dp"
    android:height="150dp" />
</shape>

You have made mistake in

<shape xmlns:android="http://schemas.android.com/apk/res/android">

above line, you have added ">" this, no need to add it.

Let me know if didn't work or you didn't understand.

  • Related