Android Drawable 系列——ClipDrawable

ClipDrawable 是一个挺好看的一个图片Drawable,操作起来也算比较简单。下面先把代码贴上来,通过例子进行说明。

main.xml文件的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:orientation="vertical" >

	<ImageView 
		android:id="@+id/image"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:src="@drawable/my_clip"
		/>
		
</LinearLayout>

这里面重点是android:sec="@drawable/my_clip",调用了这个配置文件。这个配置文件的内容是:

<?xml version="1.0" encoding="UTF-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/test" android:clipOrientation="horizontal" android:gravity="center"> </clip>
上面定义了三个属性。属性一是drawable的图片内容。第二个属性是展开的方向,第三个属性大家都经常用,不阐述。

这样,一个clipDrawable的配置文件都已经搞定了。调用一个clip配置文件,展示效果。比较简单。也很容易给项目添加一点感官上面的好处。

下面是Activity的代码:

package cn.jason.drawable; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.widget.ImageView; public class ClipDrawable extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView imageView = (ImageView) findViewById(R.id.image); final android.graphics.drawable.ClipDrawable drawable = (android.graphics.drawable.ClipDrawable) imageView.getDrawable(); final Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if (msg.what == 0x1233) { drawable.setLevel(drawable.getLevel() + 200); } } }; final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { Message msg = new Message(); msg.what= 0x1233; handler.sendMessage(msg); if (drawable.getLevel() >=10000) { timer.cancel(); } } }, 0,300); } }上面的代码定义了一个Handler,如果接收的是本程序的消息,则进行操作。特别注意。定义ClipDrawable的用法是把Drawable进行转换的。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值