Git Product home page Git Product logo

bubbleview's Introduction

BubbleView for Android

build Download build

中文版README

BubbleView is a control/container with an arrow for Android, which can be fully customized by code or XML layout file.

  • Arrow direction: up, down, left, right or none
  • Should arrow auto point to its target
  • Customizable arrow properties: size and location
  • Customizable bubble properties: color, padding, borders and corner radius
  • Bubble can be plain text view(BubbleTextView) or layout container(BubbleXxxLayout)

Download

Add jcenter() to your project-level build.gradle

allprojects {
    repositories {
        jcenter()
    }
}

Add compile 'com.cpiz.bubbleview:bubbleview:{X.Y.Z}' to your module-level build.gradle(see X.Y.Z in Releases)

dependencies {
    ...
    compile 'com.cpiz.bubbleview:bubbleview:{X.Y.Z}'
}

Specify the direction of arrow

You can use app:bb_arrowDirection attribute to specify the direction of arrow. Its value can be: Left, Up, Right, Down or None. Arrow will be placed in the middle of the corresponding edge of bubble.

Specify the direction of arrow

<com.cpiz.android.bubbleview.BubbleTextView
    android:id="@+id/bb1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@id/iv1"
    android:padding="6dp"
    android:text="ArrowRight"
    android:textColor="@android:color/white"
    app:bb_arrowDirection="Right"
    app:bb_cornerRadius="4dp"/>

Point arrow to a specific target

You can use app:bb_arrowTo attribute to specify the id of target view. The direction of arrow will be calculated automatically and it will point to the center of target.

Point arrow to specific target

<RelativeLayout
    android:id="@+id/group2"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:layout_marginBottom="30dp"
    android:background="#bdc3c7"
    android:padding="10dp">

    <ImageView
        android:id="@+id/iv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_margin="4dp"
        android:src="@android:drawable/ic_btn_speak_now"
        android:tint="#FFFFFF"/>

    <com.cpiz.android.bubbleview.BubbleTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/iv2"
        android:layout_toLeftOf="@id/iv2"
        android:padding="6dp"
        android:text="Get your apps ready for Android 6.0 Marshmallow! "
        android:textColor="@android:color/white"
        app:bb_arrowTo="@id/iv2"/>
</RelativeLayout>

Customize style

Customize style

<com.cpiz.android.bubbleview.BubbleTextView
    android:id="@+id/big4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/big2"
    android:layout_margin="4dp"
    android:layout_toRightOf="@id/big3"
    android:padding="30dp"
    android:text="WithBorder"
    android:textColor="@android:color/white"
    app:bb_arrowDirection="Down"
    app:bb_arrowHeight="10dp"
    app:bb_arrowOffset="30dp"
    app:bb_arrowWidth="40dp"
    app:bb_borderColor="@color/colorPrimary"
    app:bb_borderWidth="6dp"
    app:bb_cornerBottomLeftRadius="0dp"
    app:bb_cornerBottomRightRadius="10dp"
    app:bb_cornerTopLeftRadius="0dp"
    app:bb_cornerTopRightRadius="4dp"
    app:bb_fillColor="@android:color/holo_red_light"
    app:bb_fillPadding="4dp"/>

Use it as layout container


Beside using BubbleTextView to display text, you can also use

  • BubbleRelativeLayout
  • BubbleLinearLayout
  • BubbleFrameLayout

as bubble layout container and put customized content into it.

As container

Popup


Can use BubblePopupWindow to wrap bubble, and show as popup.

popup

  • Support touch outside to close
  • Support touch inside to close
  • Support close in time
    View rootView = LayoutInflater.from(this).inflate(R.layout.simple_text_bubble, null);
    BubbleTextView bubbleView = (BubbleTextView) rootView.findViewById(R.id.popup_bubble);
    window = new BubblePopupWindow(rootView, bubbleView);
    window.setCancelOnTouch(true);
    window.setCancelOnTouchOutside(true);
    window.setCancelOnLater(3000);
    window.showArrowTo(v, BubbleStyle.ArrowDirection.Left);

Misc.

  • Invoke methods like setBackground/setBackgroundColor of BubbleView will make the style settings invalid.

License

Copyright 2017 Cpiz

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.

bubbleview's People

Contributors

bryant1410 avatar cpiz avatar iceboundrock avatar junyuecao 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

bubbleview's Issues

添加项目依赖出现问题

我在项目目录的 build.gradle 中增加 maven { url "https://jitpack.io" }
在模块目录的 build.gradle 中增加 compile 'com.github.cpiz:BubbleView:{X.X.X}'
这样貌似不行
这个X.X.X需要具体指定为某个版本吧?

add view programmatically

Hi, i have noticed it is impossible to create view programmatically without inflating xml: the view appears transparent. Which is it the problem?

Thank you

文字显示不全

当文本内容为单个中文的时候(我用的是 门 这个字),发现气泡中的文本会显示不完全
这个该怎么解决

BubbleXXX 的內容不是在气泡中心

通过调节 padding 可以使之在中心,但是这样做有两个问题:

  1. 这样调节不准确
  2. 如果写死 padding,某个箭头方向可能内容大概在中心位置了,但是当箭头方向动态改变时,内容还是不会在气泡中心。

setpadding效果有点问题

`public void showArrowTo(View anchor, RelativePos relativePos, int marginH, int marginV) {
dismiss();

    final int screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
    final int screenHeight = Resources.getSystem().getDisplayMetrics().heightPixels;
    final int navigationBarHeight = getNavigationBarHeightDelta(anchor);
    final Rect anchorRect = getRectInWindow(anchor);

    getContentView().measure(
            View.MeasureSpec.makeMeasureSpec(screenWidth - 2 * mPadding, View.MeasureSpec.AT_MOST),
            View.MeasureSpec.makeMeasureSpec(screenHeight - 2 * mPadding, View.MeasureSpec.AT_MOST));
    final int contentWidth = getContentView().getMeasuredWidth();
    final int contentHeight = getContentView().getMeasuredHeight();
    Log.d(TAG, String.format("w:%d, h:%d", contentWidth, contentHeight));

    PopupProp outProp = new PopupProp();
    getPopupProp(screenWidth, screenHeight, navigationBarHeight, anchorRect, contentWidth, contentHeight, relativePos, marginH, marginV, mPadding, outProp);

    setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    setAnimationStyle(outProp.animationStyle);
    if (contentWidth > outProp.maxWidth) {
        setWidth(outProp.maxWidth);
    }
    mBubbleView.setArrowDirection(outProp.direction);
    mBubbleView.setArrowPosPolicy(outProp.arrowPosPolicy);
    mBubbleView.setArrowTo(anchor);
    mBubbleView.setArrowPosDelta(mArrowPosDelta);
    showAtLocation(anchor, outProp.gravity, outProp.x, outProp.y);

    if (mDelayMillis > 0) {
        setCancelOnLater(mDelayMillis);
    }
}`

其中if (contentWidth > outProp.maxWidth) {
setWidth(outProp.maxWidth);
}
这行代码无效,我padding设置成很大, outProp.maxWidth 只有100多,可最终显示出来还是900多的宽。

另外可否添加类似setpadding(top,left,right.bottom)来支持更多的定制化

是否考虑添加设置background接口?

比如我现在需要的气泡背景是渐变的颜色,这样的话单独设置color就无法做到渐变了。
如果给气泡设置成透明,然后子view设置渐变的background,那箭头也就变的透明了(箭头不算子view)。
看了看源码,setColor是直接作用在paint上,所以不知道是否考虑会加上background?
thx.

BubbleView的动态设置可行性问题

hello,我打算在一个柱状图中使用这个控件,但是不知道这个控件能不能实时的设置显示或者消失,我希望可以在点击一个柱体的时候显示在柱体上方,点击另一个柱体的时候原先的View消失,当前柱体上方显示View,同理,其他也一样,不知是否可行?也就是说,我需要的是这个View的位置是不固定的,并不是在布局中写死的.

Add Support for Drop Shadows

It does not appear that the views in this library support drop shadows using android:elevation on Android 5.0+. I have been trying to get BubbleFrameLayout to render a drop shadow with no success.

AFAICT, the views either need to integrate a ViewOutlineProvider or BubbleDrawable needs to override getOutline(). See this Stack Overflow answer for some details.

I attempted to add this myself, by adding the following to BubbleDrawable:

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void getOutline(@NonNull Outline outline) {
        super.getOutline(outline);

        outline.setConvexPath(mBorderPath);
    }

However, that results in:

java.lang.IllegalArgumentException: path must be convex
        at android.graphics.Outline.setConvexPath(Outline.java:284)
        at com.cpiz.android.bubbleview.BubbleDrawable.getOutline(BubbleDrawable.java:245)

I have not implemented this sort of low-level drawing in Android, so I am not certain how to proceed to contribute this change. But, ideally, these views would have a drop shadow, at least on Android 5.0+.

popwindow的方式显示,设置阴影的问题

尝试过在绘制BorderPath的路径上绘制一个BlurMaskFilter,边缘会被popWindow截取。使用popWindow自带的setElevation,会要求popWindow的背景色不透明,设置成不透明后箭头会被包裹在popWindow背景色内部。

添加依赖失败 ERROR: Failed to resolve: com.cpiz

你好,我已经按照README中的要求在 项目目录的 build.gradle 中增加 jcenter()
在模块目录的 build.gradle 中增加
implementation 'com.cpiz.bubbleview:bubbleview:{1.0.3}'
但是sync一直出现问题,
ERROR: Failed to resolve: com.cpiz
Affected Modules: app

请问是怎么了?

箭头没法去掉

mBubbleView.setArrowDirection(BubbleStyle.ArrowDirection.None)
箭头依然显示,无效

设置长宽,并且设置位置,背景变透明
mBubbleView.setArrowHeight(0f);
mBubbleView.setArrowWidth(0f);
new RelativePos(RelativePos.ALIGN_LEFT, RelativePos.ABOVE)

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.