在Android中,如何将图像放置在另一个图像上看起来像徽章? [英] In Android, how do I position an image on top of another to look like a badge?
本文介绍了在Android中,如何将图像放置在另一个图像上看起来像徽章?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请参见以下内容:
我尝试使用绝对布局,但已弃用.感谢您的帮助,谢谢.
I tried using Absolute layout, but that's deprecated. I appreciate your help, thanks.
推荐答案
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" />
如果您实际上想要带有动态数字/文字的徽章,则可以将第二个ImageView
设为TextView
(或ViewGroup
,例如LinearLayout
或RelativeLayout
),并为其提供背景可绘制并将文本设置为所需的文本.
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.
这篇关于在Android中,如何将图像放置在另一个图像上看起来像徽章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文