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. ACM_平面、空间分割问题(递推dp)

    折线分割平面 Time Limit: 2000/1000ms (Java/Others) Problem Description: 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要 ...

  2. ambari集群里如何正确删除历史修改记录(图文详解)

    不多说,直接上干货! 答:这些你想删除的话得得去数据库里删除,最好别删除 .  现在默认就是使用好的配置               欢迎大家,加入我的微信公众号:大数据躺过的坑        人工智 ...

  3. AJPFX实列判断一个字符串是不是对称字符串

    import java.util.Scanner; /** *        判断一个字符串是否是对称字符串 */ public class StringDemo { public static vo ...

  4. 学习笔记 第十三章 使用CSS3新布局

    第13章   使用CSS3新布局 [学习重点] 设计多列布局 设计弹性盒布局样式 使用CSS3布局技术设计适用移动需求的网页 13.1  多列布局 CSS3使用columns属性定义多列布局,用法如下 ...

  5. Android开发中使用数据库时出现java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.

    最近在开发一个 App 的时候用到了数据库,可是在使用数据库的时候就出现了一些问题,在我查询表中的一些信息时出现了一下问题: Caused by: java.lang.IllegalStateExce ...

  6. 使用Xamarin.Forms跨平台开发入门 Hello,Xamarin.Forms 第一部分 快速入门

    本文介绍了如何使用VisualStudio开发Xamarin.Forms 应用程序和使用Xamarin.Forms开发应用的基础知识,包括了构建和发布Xamarin.Forms应用的工具,概念和步骤. ...

  7. Node.js——网站访问一般流程

  8. (转)淘淘商城系列——SSM框架整合之逆向工程

    http://blog.csdn.net/yerenyuan_pku/article/details/72758590 我们知道在开发中有些工作是非常耗时但是又没有什么技术含量的,比如创建mapper ...

  9. c Xcode has incompatible definitions in different translations units

    解决方案: build > setting enable module 改为No

  10. ansible基础配置

    1.基础配置 1.1.环境 主机配置 ansible版本:2.7.4 控制端:centos7.4,IP:192.168.1.213,主机名:operation 被控制端: centos6.5,IP:1 ...