Android BGABadgeView:BGABadgeLinearLayout以整体线性布局作为BadgeView(3)

Android BGABadgeView不仅可以把某个View作为Badge,也可以把一个完整的线性布局作为BadgeView。这要用到BGABadgeLinearLayout。

我写一个例子。

写布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="zhangphil.demo.MainActivity"> <cn.bingoogolapple.badgeview.BGABadgeLinearLayout
android:id="@+id/badge"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="@android:color/holo_blue_light" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示/隐藏小红点"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Java代码:

package zhangphil.demo;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View; import cn.bingoogolapple.badgeview.BGABadgeLinearLayout;
import cn.bingoogolapple.badgeview.BGABadgeViewHelper; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final BGABadgeLinearLayout badge = (BGABadgeLinearLayout) findViewById(R.id.badge);
badge.showCirclePointBadge(); //初始化
badge.showTextBadge("9");
badge.getBadgeViewHelper().setBadgeTextSizeSp(15);
badge.getBadgeViewHelper().setBadgeTextColorInt(Color.WHITE);
badge.getBadgeViewHelper().setBadgeBgColorInt(Color.RED);
badge.getBadgeViewHelper().setDragable(true);
badge.getBadgeViewHelper().setBadgePaddingDp(6);
badge.getBadgeViewHelper().setBadgeBorderWidthDp(2);
badge.getBadgeViewHelper().setBadgeBorderColorInt(Color.WHITE);
badge.getBadgeViewHelper().setBadgeGravity(BGABadgeViewHelper.BadgeGravity.RightTop); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (badge.isShowBadge())
badge.hiddenBadge();
else {
badge.showCirclePointBadge(); //注意带上这个显示数字,否则将变成空
badge.showTextBadge("99+");
}
}
});
}
}

代码运行结果:

附录文章:

1,《仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)》链接地址:http://blog.csdn.net/zhangphil/article/details/43702953 


2,《仿短信条目右上角的红色小圆球提示气泡》链接地址:http://blog.csdn.net/zhangphil/article/details/43667727

3,《Android BGABadgeView:新消息/未接来电/未读消息/新通知圆球红点提示(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/51822514

4,《Android BGABadgeView:显示提示数字(2)》链接地址:http://blog.csdn.net/zhangphil/article/details/51828808

Android BGABadgeView:BGABadgeLinearLayout以整体线性布局作为BadgeView(3)的更多相关文章

  1. android开发------编写用户界面之线性布局

    一个好的应用程序离不开人性化的用户界面.在学习其他东西之前.理应先学习编写程序的布局(外观) 今天,我们就来学习android的UI布局----LinearLayout. LinearLayout,即 ...

  2. android开发------编写用户界面之线性布局(补充知识)

    在前面的文章中 http://www.cnblogs.com/ai-developers/p/android_linearlayout.html 我们看到了布局中有这样一个属性: layout_wei ...

  3. Android之UI编程(一):线性布局

    package com.example.fk_layout; import android.app.Activity; import android.os.Bundle; public class L ...

  4. Android BGABadgeView:BGABadgeFrameLayout(5)

     Android BGABadgeView:BGABadgeFrameLayout(5) BGABadgeView除了有自己的线性布局,相对布局外(见附录文章7,8),还实现了FrameLayou ...

  5. Android BGABadgeView:BGABadgeImageView以及BGABadgeRelativeLayout(4)

     Android BGABadgeView:BGABadgeImageView以及BGABadgeRelativeLayout(4) 在附录文章5,6,7的基础上,写一个小例子说明BGABadge ...

  6. Android布局之线性布局——LinearLayout

    本文将详细介绍线性布局的各种xml属性. xml属性 <?xml version="1.0" encoding="utf-8"?> <Line ...

  7. Android布局— — —线性布局

    以水平或垂直的方式显示界面中的控件 线性布局 语法格式: <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...

  8. android开发4:Android布局管理器1(线性布局,相对布局RelativeLayout-案例)

    控件类概述 View 可视化控件的基类 属性名称 对应方法 描述 android:background setBackgroundResource(int) 设置背景 android:clickabl ...

  9. Android -- UI布局管理,相对布局,线性布局,表格布局,绝对布局,帧布局

    1. 相对布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

随机推荐

  1. Xors on Segments Codeforces - 620F

    http://codeforces.com/problemset/problem/620/F 此题是莫队,但是不能用一般的莫队做,因为是最优化问题,没有办法在删除元素的时候维护答案. 这题的方法(好像 ...

  2. 动态规划:最大连续子序列乘积 分类: c/c++ 算法 2014-09-30 17:03 656人阅读 评论(0) 收藏

    题目描述: 给定一个浮点数序列(可能有正数.0和负数),求出一个最大的连续子序列乘积. 分析:若暴力求解,需要O(n^3)时间,太低效,故使用动态规划. 设data[i]:第i个数据,dp[i]:以第 ...

  3. PWA之serviceWorker应用

    1.serviceWorker介绍service worker是一段运行在浏览器后台的JavaScript脚本,在页面中注册并安装成功后,它可以拦截和处理网络请求,实现缓存资源并可在离线时响应用户的请 ...

  4. 数组声明的几种方式以及length属性

    声明一: int[] arr=new int[10]; for(int i=0;i<arr.length;i++){ arr[i]=i; } 声明二: int[] arr2={1,2,3}; 声 ...

  5. 如何隐藏electron窗体的菜单栏

    electron中默认带有顶部菜单栏,有时候我们的应用不需要. 再main.js文件中设置 const electron = require('electron') const path = requ ...

  6. Webform 内置对象(Response对象、Request对象,QueryString)

    Response对象:响应请求 Response.Write("<script>alert('添加成功!')</script>"); Response.Re ...

  7. 轻松搞懂Java中的自旋锁

    前言 在之前的文章<一文彻底搞懂面试中常问的各种“锁”>中介绍了Java中的各种“锁”,可能对于不是很了解这些概念的同学来说会觉得有点绕,所以我决定拆分出来,逐步详细的介绍一下这些锁的来龙 ...

  8. java课程设计全程实录——第2天

    [反思] 今天主要完成JDBC数据的连接,查阅了大量博客和书籍,繁琐而细碎.但所幸还是连上了. [日常烦心事] 下午准备用idea连测试连接的,结果电脑跑不动....CPU一度100%居高不下,ide ...

  9. SpringBoot 2.x (3):文件上传

    文件上传有两个要点 一是如何高效地上传:使用MultipartFile替代FileOutputSteam 二是上传文件的路径问题的解决:使用路径映射 文件路径通常不在classpath,而是本地的一个 ...

  10. ScrollView嵌套GridView,GridView显示不全

    最近开发有个需求是以A-Z的方式区分全国城市(搜索功能),并实现字母索引的功能(有点类似微信,不过比较坑的是用的是GridView, 并且GridView上面还有几个LinearLayout). 详细 ...