Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I create a drawable circle?

I am a beginner in android. For learning purpose, I am developing the following UI using android studio.

UI

The rectangle the screen is a textview and circle is an area where I can draw with hand.

The number of textview and circle is dynamic.

I am starting with Android, I looked at several examples but none really explained:

1) How to create a circle and enable user to draw inside it?

2) How to create a dynamic ui? I suppose this means adding view to viewgroup and dynamically creating multiple view groups etc.

Any help is greatly appreciated.

like image 754
wantro Avatar asked May 16 '26 16:05

wantro


1 Answers

Put this in a file called round_bg.xml in drawable folder

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <solid android:color="@color/white"/>
        </shape>
    </item>
</selector>

Then in your layout file you can refer to this file like this:

<View
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:background="@drawable/round_bg"/>

So you can get a round shape.

About your second question. You have to look into Recyclerview and adapters and so on.

like image 125
Tahir Ferli Avatar answered May 18 '26 04:05

Tahir Ferli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!