Clipdrawable
Clipdrawable represents a "picture fragment" from another bitmap
The Clipdrawable object is defined in an XML file using the <clip.../> element, which has the following syntax:
The following three attributes can be specified in the syntax format:
1.android:drawable: Specifies the intercepted source drawable object
2.android:cliporientaton: Specify the Intercept direction to set the horizontal or vertical intercept
3.android:gravity: Specifies the alignment of the Intercept
Note: Using the Clipdrawable object is a callable setlevel (int levle) method to set the size of the intercept, and when level is 0 o'clock, the captured picture fragment is empty, and when level is 10000, the entire picture is truncated.
Examples are as follows: slowly unfolding the landscape
Note: In the actual development, this method can be used to complete the progress of the display control.
Resource File = = "drawable folder <?xml version=" 1.0 "encoding=" Utf-8 "? ><clip xmlns:android=" http://schemas.android.com /apk/res/android "android:cliporientation=" horizontal "android:drawable=" @drawable/people "android:gravity=" Cente R "></clip> Layout file = =" <linearlayout 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 "Android:orientation=" vertical "tools:context=". Mainactivity "> <imageview android:id=" @+id/image "android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:src= "@drawable/myclip"/> </LinearLayout> Code implementation = = "Package Com.example.myclipdrawable;import Java.util.timer;import Java.util.timertask;import Android.os.Bundle;import Android.os.handler;import Android.os.message;import Android.annotation.suppresslint;import android.app.Activity; Import Android.Graphics.drawable.clipdrawable;import android.view.menu;import Android.widget.ImageView; @SuppressLint (" Handlerleak ") public class Mainactivity extends activity{@Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); ImageView img = (ImageView) This.findviewbyid (r.id.image); final clipdrawable drawable = (clipdrawable) img.getdrawable (); final Handler Hanler = new Handler () {@Overridepublic void Handlemessage (Message msg) {if (msg.what = = 1) {int value=drawable.getlevel () + 200; Drawable.setlevel (value);}}; Final Timer timer = new timer (); Timer.schedule (new TimerTask () {@Overridepublic void run () {message msg = new Message (); Msg. what = 1;hanler.sendmessage (msg);//Cancel Timer if (Drawable.getlevel () >= 10000) {timer.cancel ();}}, 0, 300);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action Bar if it is pre Sent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
Operation effect: As time changes, the picture is gradually intercepted and completed.
Android Learning Notes 34--clipdrawable Resources