Git Product home page Git Product logo

badge-view's Introduction

Badge View

Badge view is a view group providing to show a badge(or with a text) at four-corner(top-left, top-right, etc.)

Currently, it only supports one child(children) just like the framework' s android.widget.ScrollView.

This is what I learn how to write your customized view group and use it in your practice project. So, if you have any trouble or suggestion, feel free to drop me a line.

art

===

Usage

  1. via xml-layout(don' t forget to add app as xmlns)
<org.heisenberglab.badge.BadgeView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:show_badge="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:padding="4dp"
        android:text="Hello, World!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</org.heisenberglab.badge.BadgeView>
  1. via java code
FrameLayout container = (FrameLayout) findViewById(R.id.container);

// NOTE: the child view must use the same layout-params with the badge!
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT
);

BadgeView badgeView = new BadgeView(this);
badgeView.setLayoutParams(lp);

TextView tv = new TextView(this);
tv.setLayoutParams(lp);
tv.setText("This\n  is  \n  a  \n  tall  \n   text:-)");

badgeView.addBadgeView(tv);

badgeView.showBadge("...");
badgeView.setBadgeLocation(BadgeView.BadgeLocation.BOTTOM_LEFT);

// add to the container
container.addView(badgeView);

Customized attrs

To see the default value, take a look at the source code, it' s really a simple one.

<declare-styleable name="BadgeView">
  <attr name="badge_color" format="color" />
  <attr name="badge_text" format="string" />
  <attr name="badge_text_color" format="color" />
  <attr name="badge_text_size" format="dimension" />
  <attr name="normal_badge_radius" format="dimension" />
  <attr name="small_badge_radius" format="dimension" />
  <attr name="badge_margin" format="dimension" />
  <attr name="show_badge" format="boolean" />
  <attr name="show_text_badge" format="boolean" />

  <attr name="badge_location" format="enum">
    <enum name="top_left" value="0" />
    <enum name="top_right" value="1" />
    <enum name="bottom_left" value="2" />
    <enum name="bottom_right" value="3" />
  </attr>
</declare-styleable>

Notice

  1. it only supports one child(children), like it said before.

  2. the lib hasn' t published to maven central, so you must clone the lib add add it to your gradle-styled build.xml as a dependency now.

  3. the badge view simply uses the child(ren)' s width and height as its dimension. So you must specify it either use xml-layout or java code. This inconvenience would be fixed in the next version:-)

  4. required android 2.2+ (API level 8). Maybe it could support start at Android 1.0, but it deserves nothing...

License

The MIT License (MIT)

Copyright (c) 2015 longkai

The software shall be used for good, not evil.

badge-view's People

Contributors

longkai avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

volcanoscar

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.