仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)

简介: 效果图如下:仿微信、短信、来电未接数目、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)。

效果图如下:


仿微信、短信、来电未接数目、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月前
|
移动开发 小程序 API
微信外部浏览器或短信链接唤起微信小程序的解决方案
微信外部浏览器或短信链接唤起微信小程序的解决方案
128 1
|
6月前
|
JSON 小程序 前端开发
微信小程序进阶——Flex弹性布局&轮播图&会议OA项目(首页)
微信小程序进阶——Flex弹性布局&轮播图&会议OA项目(首页)
81 0
|
1月前
|
小程序 数据可视化 开发者
微信小程序开发入门介绍-布局组件
微信小程序开发入门介绍-布局组件
|
7月前
|
小程序 Android开发 iOS开发
微信小程序-虚拟支付:适用场景 / iPhone调试用支付成功,Android调用失败,提示“小程序支付能力已被限制” / “errMsg“.“requestPayment:fail banned”
微信小程序-虚拟支付:适用场景 / iPhone调试用支付成功,Android调用失败,提示“小程序支付能力已被限制” / “errMsg“.“requestPayment:fail banned”
235 0
|
4月前
|
小程序 JavaScript
微信小程序学习笔记(3) -- 伸缩布局
微信小程序学习笔记(3) -- 伸缩布局
|
8月前
|
Android开发
Android自定义View 水波气泡2
Android自定义View 水波气泡
|
5月前
|
JSON 小程序 前端开发
微信小程序首页-----布局(详细教程赶快收藏吧)
微信小程序首页-----布局(详细教程赶快收藏吧)
86 0
|
6月前
|
小程序 前端开发 安全
微信小程序之会议OA系统首页布局搭建与Mock数据交互
微信小程序之会议OA系统首页布局搭建与Mock数据交互
60 0
|
8月前
|
XML Java Android开发
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
|
8月前
|
XML Android开发 数据格式
Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误
Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误
51 0