I wanted to have a badge at corner of a layout . I managed to get badge inside the layout but not able to achieve at corner of it .
Currently my code gives me :
What i want : i want to have this badge to over right top corner of an layout .
I want something like this :
Toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@color/toolbar_color"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:text="My Assignments"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginLeft="90dp"
android:layout_weight="0.5"
android:textSize="20sp"
/>
<RelativeLayout
android:id="@+id/bell_linearlayout1"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginLeft="15dp">
<RelativeLayout
android:id="@+id/bell_linearlayout"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#75aadb">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_centerInParent="true"
android:id="@+id/cartIconImageView"
android:src="@drawable/notification"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="25dip"
android:layout_height="25dip"
android:gravity="end|top|right"
android:layout_alignParentTop="true"
android:layout_marginBottom="100dp"
android:layout_marginLeft="20dp">
<TextView
android:id="@+id/textView1"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentTop="true"
android:background="@drawable/badge" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#75aadb"
android:id="@+id/accountinfo_layout"
android:layout_gravity="center"
android:layout_marginLeft="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:src="@drawable/profile"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Drawable badge.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="#f20000" />
<stroke
android:width="2dip"
android:color="#FFF" />
<padding
android:bottom="6dp"
android:left="6dp"
android:right="6dp"
android:top="6dp" />
</shape>
Please help .