Android the system provides a horizontal progress bar for us to demonstrate the progress of running use, the horizontal progress bar shows the clip drawable technology for running progress
Here's a concrete example of how clip drawable is used.
And we have to pay attention to knowledge:
Clip0, at this time is all cropping, the picture is invisible;
When the level is 10000, the picture is not cropped, the picture is all visible
Program execution results: The first one is the initial interface, the second one is Click 5 times the interface, the third one is click 10 interface
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy3f0zgr0/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/center "width=" "height=" >
Create a new Android project called Clip drawable.
Program Structure folder:
Activity_main.xml
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " > <imageview android:id= "@+id/gril_img" android:layout_width= "Match_parent" android: layout_height= "Wrap_content" android:background= "@drawable/clip" android:contentdescription= "@string/ App_name " /> <button android:layout_width=" match_parent " android:layout_height=" Wrap_ Content " android:text=" @string/clip " android:onclick=" Change " android:layout_alignparentbottom= "True" android:layout_centerhorizontal= "true" android:layout_marginbottom= "20DP"/></ Relativelayout>
Clip.xml
<?xml version= "1.0" encoding= "Utf-8"? ><clip xmlns:android= "Http://schemas.android.com/apk/res/android" android:drawable= "@drawable/girl" android:cliporientation= "horizontal" android:gravity= "left" ></clip>
Strings.xml
<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >clipdrawable</ string> <string name= "Hello_world" >hello world!</string> <string name= "Action_settings" >settings</string><string name= "Clip" >clip</string></resources>
Mainactivity.java
Package Com.shen.clipdrawable;import Android.support.v7.app.actionbaractivity;import Android.graphics.drawable.clipdrawable;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.view;import Android.widget.imageview;public class MainActivity extends actionbaractivity {private ImageView ImageView; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);//Get ImageView control ImageView = (ImageView) Findviewbyid (r.id.gril_img);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar will//automatically handle clicks on the Home/up button so long//as you specify a parent activity in and RoidManifest.xml.int id = item.getitemid ();(id = = r.id.action_settings) {return true;} return super.onoptionsitemselected (item);} public void Change (View v) {//Get Clipdrawable object clipdrawable clipdrawable = (clipdrawable) imageview.getbackground ();// Set crop level, clip type picture The default clipping level is 0. This is all cropping. The picture is not visible;//When the level is 10000. Do not crop pictures, pictures all visible//when all is displayed. Set Invisible if (10000 = = Clipdrawable.getlevel ()) {clipdrawable.setlevel (0);} else {clipdrawable.setlevel (Clipdrawable.getlevel () + 1000);}}}
Resources in the program image:
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy3f0zgr0/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/center ">
Source
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Andorid Clip Implementation of a custom progress bar effect instance