GithubHelp home page GithubHelp logo

qstumn / badgeview Goto Github PK

View Code? Open in Web Editor NEW
4.0K 66.0 534.0 9.11 MB

支持自由定制外观、拖拽消除的MaterialDesign风格Android BadgeView

License: Apache License 2.0

Java 100.00%
badgeview badge materialdesign

badgeview's Introduction

该项目已废弃停止维护, 请不要再您的生产环境中使用

BadgeView

Download

一个可以自由定制外观、支持拖拽消除的MaterialDesign风格Android BadgeView

一些特性

  • 随意定制外观,包括Badge位置、底色、边框、阴影、文字颜色(支持透明色)、大小、内外边距等

  • Badge数字小于0时显示dot,等于0时隐藏整个Badge,在普通模式下超过99时显示99+,精确模式下显示具体值

  • 支持设置文本内容

  • 支持设置图片背景

  • 支持类似QQ的拖拽消除效果(默认关闭)

  • 支持以动画的方式隐藏Badge

how to use:

1. gradle

    compile 'q.rorbin:badgeview:1.1.3'

VERSION_CODE : here

2. code

new QBadgeView(context).bindTarget(textview).setBadgeNumber(5);

3. 方法说明

code 说明
setBadgeNumber 设置Badge数字
setBadgeText 设置Badge文本
setBadgeTextSize 设置文本字体大小
setBadgeTextColor 设置文本颜色
setExactMode 设置是否显示精确模式数值
setBadgeGravity 设置Badge相对于TargetView的位置
setGravityOffset 设置外边距
setBadgePadding 设置内边距
setBadgeBackgroundColor 设置背景色
setBadgeBackground 设置背景图片
setShowShadow 设置是否显示阴影
setOnDragStateChangedListener 打开拖拽消除模式并设置监听
stroke 描边
hide 隐藏Badge

4.在ListView或者RecyclerView中使用

可参考demo中ListViewActivityRecyclerViewActivity

5.一些注意事项

  • 请不要在xml中创建Badge
  • Badge和TargetView绑定是采用替换TargetView的Parent方式实现的,同时将Parent的Id和TargetView的Id设置成一样来保证不会在RelativeLayout中出现位置错乱问题,所以在bindTarget后再次使用findViewById(TargetViewId)得到的会是Parent而不是TargetView,此时建议使用Badge.getTargetView方法来获取TargetView,如果您有更好的解决方式并愿意和我分享,请在Issues中提交给我或者给我发邮件,谢谢。

6.更新计划

添加富文本内容

LICENSE

Copyright 2017, RorbinQiu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

badgeview's People

Contributors

qstumn avatar xxjy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

badgeview's Issues

在自定义 LinearLayout 等组合控件中使用 QBadgeView 怎样才能显示?

    View inflate = LayoutInflater.from(mContext).inflate(R.layout.base_tipview, this, true);
    Button tipBtn = (Button) inflate.findViewById(R.id.button);
    Badge badge = new QBadgeView(mContext);
    badge.bindTarget(tipBtn);
    badge.setBadgeNumber(5);
    badge.setBadgeBackgroundColor(getResources().getColor(R.color.home_title_color));
    badge.setBadgeGravity(Gravity.END | Gravity.TOP);

不显示 QBadgeView

RadioButton使用异常

new QBadgeView(this).bindTarget(findViewById(R.id.home_rb_online)).setBadgeNumber(bytesList.size());
这个id指向的是我的radiobutton,然后我还有一个地方Radiogroup设置的有监听,然后,一旦我在这里绑定了这个控件,那边的监听就无效了,感觉应该是点击事件被拦截了。难道这种组合按钮还需要单独去获取再设置红点的显示与否吗?

希望增加设置初始半径参数的接口

目前默认的Badge在很多场景下显得有些大了。
刚刚大概看了眼源码,是不是增加一个mDefalutRadius的set接口就可以了呢?没有太仔细看,总之感觉7dp确实大了点。

另,代码风格很赞!

在fragment里面不显示

在fragment里面创建,使用的是textview,但是就是不显示效果,在activity里面构建是显示的

请求支持setText(String)

在实际生产中遇到了需要通过角标删除图片的业务逻辑,望加入更通用的setText(String)的特性。
(有点想pr了。。)

不能设置?Gravity.END | Gravity.CENTER

不能设置?Gravity.END | Gravity.CENTER;
only support Gravity.START | Gravity.TOP , Gravity.END | Gravity.TOP , Gravity.START | Gravity.BOTTOM , Gravity.END | Gravity.BOTTOM , Gravity.CENTER?

setid()的疑问!?

QBadgeView --> lien 157 这个地方 为什么是targetView.setId(View.NO_ID); 而不是用 targetView.setId(targetView.getId()); 这样不是设置了 新view的id和原始的一样了吗? 应该就可以解决点击事件的问题了吧?

希望可以增加stroke属性

在去掉阴影并且图片本身是红色的情况下,红色的角标搭配起来不好看,如果周围能有一圈白边就好了。希望能增加stroke属性,并且可以自定义颜色。

设置居中方式无效

TOP直接不显示了. 只有CENTER有效. 默认的是在图片的左边居中.
我是给imageView设置的

关于radiogroup中radiobutton添加角标的问题

radiogroup中radiobutton添加角标,貌似那个radiobutton的互斥事件就失效了。这应该是radiobutton的parentview也就是radiogroup被替换了的原因吧,怎么处理这个问题呢?

ImageButton设置gravity为end和top无效

RT,target为ImageButton,style为ActionButton放到了顶部导航栏,设置gravity为Gravity.END | Gravity.TOP,小红点始终位于右侧中间位置,而不是右上角,新手求解答~

如果是放在recyclerview里面的控件,通过更新item, 因为复用,会有点问题。

if(badge==null){
badge = new QBadgeView(context).bindTarget(img_type);
badge.setBadgeGravity(Gravity.END | Gravity.TOP);
badge.setGravityOffset(DensityUtil.dip2px(context,6), DensityUtil.dip2px(context,6), false);
badge.setBadgePadding(3, true);
badge.setBadgeTextSize(10, true);
badge.setBadgeTextColor(context.getResources().getColor(R.color.mine_secretary_color));
badge.setBadgeBackgroundColor(Color.parseColor("#ffffff"));
}
badge.setBadgeNumber(typeBean.getMesCount());

hide方法报空指针异常

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.addView(android.view.View, android.view.ViewGroup$LayoutParams)' on a null object reference

QBadgeView.screenFromWindow(QBadgeView.java:227)

我使用setVisibility(View.GONE);来代替hide

为什么不能在xml中加载呢? 另外拖动时cpu占用很大

你好, 我有注意到你在文档中提醒不要在 xml 中使用, 我想知道为什么不能使用, 所以尝试使用了下, log 日志只显示了error inflating..., 没有具体指出为什么不能加载.

另外追踪调用效率, 发现在拖动时 系统函数 nSyncAndDrawFrame 占用时间非常长, 达到了 10ms 量级, 测试onDraw 方法直接 return, 占用时间还是一样长, 所以不是 onDraw 里面的问题.

以上两个问题一直让我困惑, 希望你抽空能帮我解答一下疑惑.

显示位置问题

new QBadgeView(mActivity).bindTarget(imageView).setBadgeNumber(5).setBadgeGravity(Gravity.END | Gravity.TOP);
我用的是Gravity.END | Gravity.TOP 显示在imageView右上角 运行起来是在左下角?这个还需要其他设置吗

出现以下bug

``java.lang.RuntimeException:Unable to start activity ComponentInfo{com.twl.qichechaoren_business/com.twl.qichechaoren_business.purchase.view.PurchaseManageActivity}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.CompoundButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/rb_cart. Make sure other views do not use the same id.

BadgeView inside RecyclerView

I added BadgeView to RecyclerView and I have some problem. For dismissing of Badge I use badge.hide(true); But when I scroll RecyclerView and after that trying hide Badge I see animation on wrong place.

May you help me?

横竖屏切换时

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fly.market/com.fly.market.activity.MainActivity}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.HorizontalScrollView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/app_tab_bottom. Make sure other views do not use the same id.

是不是copy相同ID 的VIew 问题?

显示问题

我设置的是Gravity.START | Gravity.BOTTOM,可是有一半看不到了

setBadgeNumber(0)时不隐藏

我在onResume方法中调用

public void setMessageNum() {
    AppLog.redLog("sk", "MsgNum:" + Constant.MESNUM);
    MsgBadge = new QBadgeView(getActivity()).bindTarget(img_message).setGravityOffset(0, -3, true).setShowShadow(false).setBadgeNumber(Constant.MESNUM);
}

日志打印 E/sk: MsgNum:0

但是没有隐藏badge

Gravity.CENTER ignores setGravityOffset()

I want to set badge offset from center.
Current implementation does not apply the offset if CENTER is set.
Can you add mGravityOffsetY and mGravityOffsetX to mBadgeCenter if gravity is CENTER too?

Example:
Gravity.CENTER | Gravity.TOP: mBadgeCenter.x = (mWidth / 2f) + (mGravityOffsetX + mBadgePadding); mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f; break;

bugly检测到线上崩溃

场景为:
badgeview 版本1.1.1
主界面下方使用RadioGroup含有固定个数的RadioBtn,然后通过badgeview给radiobtn设置红点
自己手机没有遇到这样的崩溃事件
崩溃机型:OPPO R9 Plustm A
Cpu架构:arm64-v8a

具体日志为:
java.lang.RuntimeException:Unable to start activity ComponentInfo{com.tsou.yezonghui/com.tsou.yezonghui.activity.MainHolderActivity}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.CompoundButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/btn1. Make sure other views do not use the same id.

2 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2430)
3 ......
4 Caused by:
5 java.lang.IllegalArgumentException:Wrong state class, expecting View State but received class android.widget.CompoundButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/btn1. Make sure other views do not use the same id.
6 android.view.View.onRestoreInstanceState(View.java:13851)
7 android.view.View.dispatchRestoreInstanceState(View.java:13827)
8 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2904)
9 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2910)
10 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2910)
11 android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2910)
12 android.view.View.restoreHierarchyState(View.java:13805)
13 com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2035)
14 android.app.Activity.onRestoreInstanceState(Activity.java:1054)
15 com.tsou.yezonghui.activity.k.onRestoreInstanceState(Unknown Source)
16 android.app.Activity.performRestoreInstanceState(Activity.java:1009)
17 android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1165)
18 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
19 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2503)
20 android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4099)
21 android.app.ActivityThread.access$1000(ActivityThread.java:160)
22 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
23 android.os.Handler.dispatchMessage(Handler.java:102)
24 android.os.Looper.loop(Looper.java:179)
25 android.app.ActivityThread.main(ActivityThread.java:5491)
26 java.lang.reflect.Method.invoke(Native Method)
27 java.lang.reflect.Method.invoke(Method.java:372)
28 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:961)
29 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.