[英]Android: how to create a notification badge for an icon?
I have an ImageView
like this:我有一个这样的ImageView
:
<ImageView android:id="@+id/historyIcon"
tools:src="@drawable/to_delete"
android:scaleType="centerCrop"
android:layout_alignParentLeft="true"
android:layout_width="32dp"
android:layout_height="32dp" />
How can I add a badge image on the top right corner of this ImageView
?如何在此ImageView
右上角添加徽章图像? Is it possible to add a secondary image on the same ImageView
?是否可以在同一个ImageView
上添加次要图像?
Example image:示例图像:
This is very simple UI, which you can do with help of two separate image view in one Parent Layout.这是一个非常简单的用户界面,您可以在一个父布局中的两个独立图像视图的帮助下完成。 i give you one simple idea below, but you can try any other way to doing same:我在下面给你一个简单的想法,但你可以尝试任何其他方式来做同样的事情:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image1"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@android:drawable/btn_dialog"/>
<ImageView
android:id="@+id/image2"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_toEndOf="@+id/image1"
android:layout_marginLeft="-15dp"
android:src="@android:drawable/btn_dialog"/>
</RelativeLayout>
Just change your image source in place of src in both image view.只需在两个图像视图中更改图像源代替src 。 the 1st image view display main (large) image, and the 2nd one display small image which is on top of right corner.第一个图像视图显示主(大)图像,第二个显示位于右上角的小图像。
Yes its possible try this是的,它可能试试这个
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:id="@+id/historyIcon"
tools:src="@drawable/to_delete" />
<ImageView
android:padding="10dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:gravity="center">
<ImageView
android:id="@+id/xx"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:src="@mipmap/mprofilelogo"/>
<ImageView
android:id="@+id/ss"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@mipmap/ccc"
android:src="@null"/>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.