Reputation: 3760
Does anyone know, is there any library on Github for example, or something else for adding a circle counter on top of an image:
Actually, I can create a new FrameLayout
and position every element, but I am not sure that this is the right way. I searched for something like that, but I didn't find anything.
Upvotes: 0
Views: 819
Reputation: 1073
Create a drawable file name badge_background.xml
and paste the code below.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#FF0000" />
</shape>
Then set this drawable to the background of the textview, like below.
<FrameLayout android:id="@+id/viewLayout" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_weight="1" android:padding="12dp">
<ImageView android:id="@+id/view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:contentDescription="@string/imageDescription" android:src="@drawable/view" />
<TextView android:id="@+id/viewBad" android:layout_width="20dip" android:layout_height="20dip" android:clickable="false" android:layout_marginStart="5dp" android:layout_gravity="top|center_horizontal" android:background="@drawable/badge_background" android:gravity="top|center_horizontal" android:text="5" android:textColor="@color/white" android:visibility="gone" />
</FrameLayout>
Upvotes: 1