问题
Please see below:
I tried using Absolute layout, but that's deprecated. I appreciate your help, thanks.
回答1:
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 actually want a badge with a dynamic number/text, then you can make the second ImageView
a TextView
(or a ViewGroup
such as LinearLayout
or RelativeLayout
) and give it a background drawable and set the text to what you want.
回答2:
Have a look at the ViewBadger project on github(but keep in mind that you shouldn't try to copy other platforms UI elements in android apps).
来源:https://stackoverflow.com/questions/11090015/in-android-how-do-i-position-an-image-on-top-of-another-to-look-like-a-badge