本文主要是介绍Android ClipDrawable资源,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文内容摘自《疯狂Android讲义 第三版-李刚著作》
my_clip_1.xml:
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"android:drawable="@drawable/bg"android:clipOrientation="horizontal"android:gravity="center"></clip>
<ImageViewandroid:id="@+id/image_clip"android:layout_width="match_parent"android:layout_height="match_parent"android:src="@drawable/my_clip_1"/>
java代码:
package shortcut.song.com.myapplication;import android.graphics.drawable.ClipDrawable;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;import java.util.Timer;
import java.util.TimerTask;public class ResourceActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_resource);final ImageView imageView = (ImageView)findViewById(R.id.image_clip);final ClipDrawable clipDrawable = (ClipDrawable)imageView.getDrawable();final Handler mHandler = new Handler(){@Overridepublic void handleMessage(Message msg) {super.handleMessage(msg);if (msg.what == 0x1234){clipDrawable.setLevel(clipDrawable.getLevel() + 180);}}};final Timer mTimer = new Timer();mTimer.schedule(new TimerTask() {@Overridepublic void run() {Message msg = new Message();msg.what = 0x1234;mHandler.sendMessage(msg);if (clipDrawable.getLevel() > 10000){mTimer.cancel();}}}, 0, 320);}
}
这篇关于Android ClipDrawable资源的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!