仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android(安卓)XML布局文件实现)
16lz
2021-01-26
效果图如下:
仿微信、短信、来电未接数目、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)。这种实现方式主要有两种途径:(1)重写View的onDraw()。(2)写布局文件实现。现在使用布局文件实现,主要利用FrameLayout的布局覆盖特性实现上述功能。随意一个图片,本例中以eclipse自动产生的ic_luancher.png(就是Android小机器人)图片为例。将ic_launcher作为一个ImageView的src。将此ImageView处理成圆角图(不是本例的重点)。再写一个FrameLayout,内部嵌套一个TextView,此TextView以一个红色圆作为背景。
layout目录下的 round_corner_imageview.xml :
[html] view plain copy
- <FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="3dip">
- <ImageView
- android:layout_marginTop="10dip"
- android:layout_marginLeft="10dip"
- android:layout_marginRight="10dip"
- android:id="@+id/imageView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/ic_launcher"
- android:background="@drawable/round"/>
- <FrameLayout
- android:layout_gravity="right"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView
- android:layout_width="25dip"
- android:layout_height="25dip"
- android:background="@drawable/tips_circle"
- android:gravity="center"
- android:text="5"
- android:textSize="15dip"
- android:textStyle="bold"
- android:textColor="@android:color/white"/>
- </FrameLayout>
- </FrameLayout>
drawable目录下(1)round.xml,(2)tips_circle.xml
round.xml
[html] view plain copy- <?xmlversion="1.0"encoding="UTF-8"?>
- <shapexmlns:android="http://schemas.android.com/apk/res/android">
- <!--背景填充颜色值-->
- <solidandroid:color="#FFA500"/>
- <!--radius值越大,越趋于圆形-->
- <cornersandroid:radius="20dip"/>
- <!--圆角图像内部填充四周的大小,将会以此挤压内部布置的view-->
- <padding
- android:bottom="3dip"
- android:left="3dip"
- android:right="3dip"
- android:top="3dip"/>
- </shape>
tips_circle.xml
[html] view plain copy
- <?xmlversion="1.0"encoding="utf-8"?>
- <shape
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval"
- android:useLevel="false">
- <solidandroid:color="#FF0000"/>
- </shape>
更多相关文章
- android程序自动化生成apk的过程
- Android(安卓)eclipse 项目R文件无法生成
- python: android批量多渠道打包
- Android通过URI获取文件路径
- Android(安卓)沉浸式状态栏原理
- android ndk生成第三方库的so方法(ndk-build,Application.mk,Andro
- recovery 的原理已经 rom制作的知识
- Android(安卓)Developers:ProGuard
- Android学习记录(4)—在java中学习多线程下载的基本原理和基本用法