1

I want to show a number on the corner of rounded image of a user similar to messenger which hows the image of facebook or messenger icon. Number will be a simple integer below 100.

enter image description here

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39

2 Answers2

7

You can do it with a TextView and ImageView inside a RelativeLayout like this :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="20dp"
    android:background="#786993">
    <ImageView
        android:id="@+id/image"
        android:src="@drawable/q_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/tab_counter_text"
        android:text="20"
        android:layout_alignRight="@id/image"
        android:layout_alignBottom="@id/image"
        android:layout_width="20dp"
        android:layout_gravity="center"
        android:background="@drawable/circle_white"
        android:layout_height="20dp"
        android:gravity="center"
        android:textColor="#786993"
        android:textSize="12sp" />
</RelativeLayout>

and you can set the background of the TextView as a custom circle drawable like this(circle_white.xml) :

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

Output :

enter image description here

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39
1
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/container_view">
    <ImageView
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:src="@drawable/image"/>
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="10"
        android:layout_gravity="bottom|end"
        android:textColor="@color/colorPrimary"
        android:background="@drawable/circleBackground"/>

</FrameLayout>
thealeksandr
  • 1,686
  • 12
  • 17