Andorid Clip implements a custom progress bar effect instance

Source: Internet
Author: User

The Android system provides a horizontal progress bar for us to show progress, and the horizontal progress bar is used to display the progress of the clip drawable technology
Here's a concrete example to illustrate the use of clip drawable.

There is a knowledge to note:

Clip type of picture default clipping level is 0, at this time is all cropping, the picture is not visible;
When the level is 10000, the picture is not cropped and the picture is all visible

The results of the program run: The first is the initial interface, the second is a click of 5 times the interface, the third one for the click 10 interface


Create a new Android project called Clip drawable.

Program Structure Directory:



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 default clipping level is 0, at this time is all cropping, the picture is not visible;//When the level is 10000, the picture is not cropped, the picture is 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:



SOURCE download

Andorid Clip implements a custom progress bar effect instance

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.