话就不多说了,直接上代码。
二、源码
步骤一、在根目录下创建 drawable文件夹,然后在drawable里创建clip_btimap.xml
代码如下 | 复制代码 |
<?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> |
步骤二、activity_main.xml
代码如下 | 复制代码 |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
步骤三、MainActivity
代码如下 | 复制代码 |
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; /** * * 入口类 * @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); //获取图片所显示的ClipDrawble对象 final ClipDrawable drawable = (ClipDrawable)imageView.getDrawable(); final Handler handler = new Handler() { public void handleMessage(Message msg) { if(msg.what == 0x1233) { if(drawable.getLevel() >= 10000){ drawable.setLevel(0); } //修改ClipDrawable的level值 drawable.setLevel(drawable.getLevel() +500); } } }; //时间类 final Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { Message msg = new Message(); msg.what = 0x1233; //发送消息,通知应用修改ClipDrawable对象的level值 handler.sendMessage(msg); //取消定时器 // if(drawable.getLevel() >= 10000) // { // timer.cancel(); // } } },0,300); } } |
时间: 2024-10-02 10:55:46