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