效果图如下:



仿微信、短信、来电未接数目、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
  1. <FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:padding="3dip">
  5. <ImageView
  6. android:layout_marginTop="10dip"
  7. android:layout_marginLeft="10dip"
  8. android:layout_marginRight="10dip"
  9. android:id="@+id/imageView"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:src="@drawable/ic_launcher"
  13. android:background="@drawable/round"/>
  14. <FrameLayout
  15. android:layout_gravity="right"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content">
  18. <TextView
  19. android:layout_width="25dip"
  20. android:layout_height="25dip"
  21. android:background="@drawable/tips_circle"
  22. android:gravity="center"
  23. android:text="5"
  24. android:textSize="15dip"
  25. android:textStyle="bold"
  26. android:textColor="@android:color/white"/>
  27. </FrameLayout>
  28. </FrameLayout>


drawable目录下(1)round.xml,(2)tips_circle.xml


round.xml

[html] view plain copy
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <shapexmlns:android="http://schemas.android.com/apk/res/android">
  3. <!--背景填充颜色值-->
  4. <solidandroid:color="#FFA500"/>
  5. <!--radius值越大,越趋于圆形-->
  6. <cornersandroid:radius="20dip"/>
  7. <!--圆角图像内部填充四周的大小,将会以此挤压内部布置的view-->
  8. <padding
  9. android:bottom="3dip"
  10. android:left="3dip"
  11. android:right="3dip"
  12. android:top="3dip"/>
  13. </shape>


tips_circle.xml

[html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <shape
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:shape="oval"
  5. android:useLevel="false">
  6. <solidandroid:color="#FF0000"/>
  7. </shape>


更多相关文章

  1. android程序自动化生成apk的过程
  2. Android(安卓)eclipse 项目R文件无法生成
  3. python: android批量多渠道打包
  4. Android通过URI获取文件路径
  5. Android(安卓)沉浸式状态栏原理
  6. android ndk生成第三方库的so方法(ndk-build,Application.mk,Andro
  7. recovery 的原理已经 rom制作的知识
  8. Android(安卓)Developers:ProGuard
  9. Android学习记录(4)—在java中学习多线程下载的基本原理和基本用法

随机推荐

  1. Android设置TextView的行间距、行高。
  2. Android再学习-20141018-布局-进度条
  3. Android起步--简单的乘法
  4. Android学习指南之三十七:Android传感器编
  5. Android应用开发相关下载资源(2014/12/14
  6. Android如何设置TextView的行间距、行高
  7. ndk完整编译cocos2dx项目总结
  8. Android 让一个控件或布局居于底部的办法
  9. Android蓝牙开发浅析
  10. android EditText输入限制