0
点赞
收藏
分享

微信扫一扫

android之 clipdraw 在 .xml中的使用 图片进度条 cpu扫描


lipDraw 代表从其他位图上截取的一个“图片片段”。

                  在xml文件中定义ClipDraw对象使用<clip... />, 其结构如下:


[html]  view plain  copy



1. <?xml version="1.0" encoding="UTF-8"?>  
2. <clip xmlns:android="http://schemas.android.com/apk/res/android"   
3. android:drawable="@drawable/shuangta"   
4. android:clipOrientation=["vertical"]|["vertical"]   
5. android:gravity="top" | "bottom" | "left" | "right" | "center_vertical"|"fill_vertical" | "center_horizontal" | "fill_horizontal" | "center" |"fill" | "clip_vertical" | "clip_horizontal">   
6. </clip>


        

       

 

         -->  android:drawable :指定截取的源Drawable对象。

        --> android:clipOrientation : 指定截取方向,可设置水平截取或者垂直截取。

        --> android:gravity : 指定截取时对齐的方式。

        使用ClipDraw对象时可调用setLevel(int level) 方法来设置截取的区域大小,当level为0时,截取的图片片段为空;当level为10000时,

  截取整张图片。

 

 

android之 clipdraw 在 .xml中的使用 图片进度条 cpu扫描_android

 

下面实例:每200ms设置一次Level 的大小, 以实现上图图卷展开的效果:

.xml 文件 应放在Drawable 目录下,在layout 文件中调用:

 


[html]  view plain  copy



1. <?xml version="1.0" encoding="UTF-8"?>  
2. <clip xmlns:android="http://schemas.android.com/apk/res/android"   
3. android:drawable="@drawable/we"   
4. android:clipOrientation="horizontal"   
5. android:gravity="left">   
6. </clip>


 

Java 程序代码:

 


[java]  view plain  copy


1. public class ClipDrawableTest extends Activity  
2. {  
3. @Override  
4. public void onCreate(Bundle savedInstanceState)  
5.     {  
6. super.onCreate(savedInstanceState);  
7.         setContentView(R.layout.main);  
8.         ImageView imageview = (ImageView) findViewById(R.id.image);  
9. // 实例化ClipDrawable对象  
10. final ClipDrawable drawable = (ClipDrawable)  
11.             imageview.getDrawable();  
12. final Handler handler = new Handler()  
13.         {  
14. @Override  
15. public void handleMessage(Message msg)  
16.             {  
17.                   
18. if (msg.what == 0x1233)  
19.                 {  
20. //更改截取的区域大小ֵ  
21. 100);  
22. if (drawable.getLevel() >= 10000)  
23.                     {  
24. //显示完整图片后重新开始  
25. 0);  
26.                     }  
27.                 }  
28.             }  
29.         };  
30. final Timer timer = new Timer();  
31. new TimerTask()  
32.         {  
33. @Override  
34. public void run()  
35.             {  
36. new Message();  
37. 0x1233;  
38.                   
39.                 handler.sendMessage(msg);  
40.                   
41.             }  
42. 0, 200);  
43.     }  
44. }  
45.

举报

相关推荐

0 条评论