仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)
来源:互联网 发布:如何优化你的页面 编辑:程序博客网 时间:2024/04/29 11:11
效果图如下:
仿微信、短信、来电未接数目、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 :
- <FrameLayout xmlns: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
- <?xml version="1.0" encoding="UTF-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <!-- 背景填充颜色值 -->
- <solid android:color="#FFA500" />
- <!-- radius值越大,越趋于圆形 -->
- <corners android:radius="20dip" />
- <!-- 圆角图像内部填充四周的大小 ,将会以此挤压内部布置的view -->
- <padding
- android:bottom="3dip"
- android:left="3dip"
- android:right="3dip"
- android:top="3dip" />
- </shape>
tips_circle.xml
- <?xml version="1.0" encoding="utf-8"?>
- <shape
- xmlns:android= "http://schemas.android.com/apk/res/android"
- android:shape= "oval"
- android:useLevel= "false" >
- <solid android:color= "#FF0000" />
- </shape>
1 0
- 仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)
- 仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)
- Android实现图标右上角红色小圆球提示气泡
- Android实现图标右上角红色小圆球提示气泡(不需要导入第三方)
- 仿短信条目右上角的红色小圆球提示气泡
- Android 实现控件右上角显示消息数量气泡(badge)
- 右上角删除小红叉显示(基于Android XML布局文件实现)
- 模仿短信模式的显示消息数目的xml布局 和 cmd查看手机短信步骤
- Android开源BezierView:仿QQ未读消息99+条的红色气泡
- Android开源BezierView:仿QQ未读消息99+条的红色气泡
- Android开源BezierView:仿QQ未读消息99+条的红色气泡
- Android自定义View仿QQ消息拖拽气泡实现
- 小圆球提示气泡(不需要导入第三方)
- android 桌面快捷键未读的消息数目,未接来电,短信提醒那个右上角的数字
- android 桌面快捷键未读的消息数目,未接来电,短信提醒那个右上角的数字
- (十三)QQ 消息气泡
- android实现类似在短信图标右上角显示短信个数的效果
- 实现类似QQ气泡消息的样式
- android实现沉浸式之systembartintmanager
- Android ListView代码笔记
- 亮度、对比度、直方图均衡化
- SpeechAudioFormatType Enum
- JDBC操作数据库的基本框架
- 仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)
- cocos2dx js 常用端版本判断记录
- VPN是什么?有什么用?
- Andorid 实例源码:音频录制
- 学习笔记(一)省略std
- React-Native学习指南
- SVM(支持向量机)中拉格朗日乘子法(Lagrange Multiplier) 和KKT条件
- CentOS6.5 安装mysq
- iOS设置颜色渐变