在Android中,如何将图像放在另一个上面看起来像徽章?

Sta*_*wed 6 android android-ui android-layout

请看下面:

iPhone徽章

我尝试使用绝对布局,但不推荐使用.感谢您的帮助,谢谢.

Sam*_*zor 16

RelativeLayout是一个很好的选择.

<?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" />
Run Code Online (Sandbox Code Playgroud)

如果你真的想要一个带有动态数字/文本的徽章,那么你可以制作第二ImageViewTextView(或ViewGroup类似的LinearLayoutRelativeLayout)并给它一个背景可绘制并将文本设置为你想要的.


Luk*_*rog 7

看看github 上的ViewBadger项目(但请记住,你不应该尝试复制Android应用程序中的其他平台UI元素).