In Android, how to position an image on top of another to look like an icon?

See below:

iPhone badges

I tried using the Absolute layout, but this is not recommended. I appreciate your help, thanks.

+6
source share
2 answers

RelativeLayout is a great option.

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:scaleType="centerCrop" android:src="@drawable/iconImage" /> <ImageView android:id="@+id/badge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/icon" android:layout_alignTop="@+id/icon" android:src="@drawable/badge" /> 

If you really need an icon with a dynamic number / text, you can make a second ImageView a TextView (or a ViewGroup , such as LinearLayout or RelativeLayout ), and give it a background to cut and set the text according to what you want.

+16
source

Check out the ViewBadger project on github (but keep in mind that you shouldn't try to copy UI elements in Android apps).

+7
source

Source: https://habr.com/ru/post/918400/


All Articles