Android Clipdrawable to achieve a circular progress bar effect

Source: Internet
Author: User
Tags xmlns


Words will not say more, directly on the code.

Second, the source code

Step one, create the Drawable folder under the root directory, and then create the Clip_btimap.xml in the drawable

The code is as follows Copy Code

<?xml version= "1.0" encoding= "Utf-8"?>
<clip xmlns:android= "Http://schemas.android.com/apk/res/android"
android:cliporientation= "Horizontal"
android:drawable= "@drawable/t2"
android:gravity= "Left|start" >
</clip>

Step Two, Activity_main.xml

The code is as follows Copy Code

<framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:orientation= "Vertical" >

<imageview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:src= "@drawable/t1"/>

<imageview
Android:id= "@+id/iv_image"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:src= "@drawable/clip_btimap"/>

</FrameLayout>

Step three, Mainactivity

The code is as follows Copy Code


Package com.msquirrel.main;

Import Java.util.Timer;
Import Java.util.TimerTask;

Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import android.app.Activity;
Import android.graphics.drawable.ClipDrawable;
Import Android.view.Menu;
Import Android.widget.ImageView;
/**
*
* Entry Class
* @author Msquirrel
*
*/
public class Mainactivity extends activity {

Private ImageView ImageView = null;

@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
ImageView = (ImageView) Findviewbyid (r.id.iv_image);
Get the Clipdrawble object displayed by the picture
Final clipdrawable drawable = (clipdrawable) imageview.getdrawable ();
Final Handler Handler = new Handler ()
{
public void Handlemessage (msg)
{
if (msg.what = = 0x1233)
{
if (Drawable.getlevel () >= 10000) {
Drawable.setlevel (0);
}
Modify the level value of a clipdrawable
Drawable.setlevel (Drawable.getlevel () +500);
}
}
};

Time class
Final Timer timer = new timer ();
Timer.schedule (New TimerTask ()
{
public void Run ()
{
msg = new Message ();
Msg.what = 0x1233;
Sends a message informing the application of the level value of the modified Clipdrawable object
Handler.sendmessage (msg);
Cancel Timer
if (Drawable.getlevel () >= 10000)
//                {
Timer.cancel ();
//                }
}
},0,300);
}
}

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.