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); } } |