Android badge ImageView (Weibo, QQ message prompt), androidimageview

Source: Internet
Author: User

Android badge ImageView (Weibo, QQ message prompt), androidimageview

Corner Painting Process: Use the paint brush to measure the width of a character as the radius (R) of the corner background, and then determine the total length of the input string.
If there is only one character: Draw a circle with the R radius and write a number in the circle
If there are more than two characters, you can not simply use a circle, use a brush to measure the complete length of the string (len), and then draw a circle in the upper right corner, place the len Length on the left of the center of the circle as the center of the circle and draw another circle. Finally, the upper and lower vertices of the two circles (four in total) form a rectangle for filling.

Source Code address: https://github.com/SiKang123/AndroidToolBox

The effect is as follows:

Integration Method

Add under build. gradle of the Project

allprojects {    repositories {        ...        maven { url 'https://jitpack.io' }    }}

Add under build. gradle of Module

dependencies {       compile 'com.github.SiKang123:AndroidToolBox:1.0'}
Usage

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:gravity="center_horizontal"    android:orientation="vertical"    android:paddingTop="50dp">    <android.simple.toolbox.widget.CornerImageView        android:layout_width="50dp"        android:layout_height="50dp"        android:layout_margin="20dp"        android:src="@mipmap/ic_launcher"        app:cornerBackground="@color/red"        app:cornerText="9"        app:cornerTextColor="@color/white"        app:cornerTextSize="11dp" />    <android.simple.toolbox.widget.CornerImageView        android:layout_width="50dp"        android:layout_height="50dp"        android:layout_margin="20dp"        android:src="@mipmap/ic_launcher"        app:cornerBackground="@color/red"        app:cornerText="99"        app:cornerTextColor="@color/white"        app:cornerTextSize="11dp" />    <android.simple.toolbox.widget.CornerImageView        android:layout_width="50dp"        android:layout_height="50dp"        android:layout_margin="20dp"        android:src="@mipmap/ic_launcher"        app:cornerBackground="@color/red"        app:cornerText="999"        app:cornerTextColor="@color/white"        app:cornerTextSize="11dp" />    <android.simple.toolbox.widget.CornerImageView        android:id="@+id/progress_imageview"        android:layout_width="60dp"        android:layout_height="60dp"        android:layout_margin="20dp"        android:src="@mipmap/ic_launcher"        app:cornerBackground="@mipmap/shanchu"        app:cornerLoadColor="@color/alpha_black_35"        app:cornerRadius="7dp" /></LinearLayout>

Activtiy:

@ Override protected void onCreate (@ Nullable Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_cornerimage); // set the loading progress of the last image to 20%, and add the Click Event CornerImageView imageView = (CornerImageView) findViewById (R. id. progress_imageview); imageView. progress (20); imageView. setOnCornerClickListener (new CornerImageView. onCornerClickListener () {@ Override public void onCornerClickListener (View view) {Toast. makeText (SimpleCornerImageActivity. this, "Badge clicked", Toast. LENGTH_SHORT ). show ();}});}
Top
0
Step on
0
View comments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.