An instance of Andorid Clip for customizing the progress bar effect.

Source: Internet
Author: User

An instance of Andorid Clip for customizing the progress bar effect.
The Android system provides a horizontal progress bar for us to display the progress. The horizontal progress bar uses the Clip Drawable technology to display the progress.
The following describes the use of Clip Drawable through a specific instance.

Note the following:

The default cropping level of a Clip image is 0. All images are cropped and invisible;
When the level is 10000, the image is not cropped and all images are visible.

Program running result: the first interface is the initial interface, the second interface is the 5-click interface, and the third interface is the 10-click interface.


Create an Android project named 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); // obtain the 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 present. 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 AndroidManifest.xml.int id = item. getItemId (); if (id = R. id. action_settings) {return true;} return super. onOptionsItemSelected (item);} public void change (View v) {// obtain the ClipDrawable object ClipDrawable clipDrawable = (ClipDrawable) imageView. getBackground (); // sets the cropping level. The default cropping level of a Clip image is 0. At this time, all cropping is performed and the image cannot be seen. // when the cropping level is 10000, no cropping is performed, all images visible // when all images are displayed, set invisible if (10000 = clipDrawable. getLevel () {clipDrawable. setLevel (0);} else {clipDrawable. setLevel (clipDrawable. getLevel () + 1000 );}}}


Resource images used in the program:



Source code download

Related Article

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.