首页 > 代码库 > 实现图片缓慢展开功能
实现图片缓慢展开功能
//要用到clipdrawble,xml功能如下,在drawble目录下新建,类型选择为clip(注意AS不会提示)
<?xml version="1.0" encoding="utf-8"?><clip xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/a" android:clipOrientation="horizontal" android:gravity="center"></clip>
//IMG的XML
<ImageView
android:id="@+id/img"
android:src="http://www.mamicode.com/@drawable/clip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
//JAVA代码如下
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;
public class MainActivity extends AppCompatActivity {
private ImageView img;
private ClipDrawable clip;
private MyHandler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
img = (ImageView) findViewById(R.id.img);
clip=(ClipDrawable) img.getDrawable();
handler=new MyHandler();
MyThread thread=new MyThread();
new Thread(thread).start();
}
private class MyThread implements Runnable{
@Override
public void run() {
while(true){
try {
Message msg=handler.obtainMessage();
msg.what=0x123;
msg.sendToTarget();
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private class MyHandler extends Handler{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==0x123){
clip.setLevel(clip.getLevel()+100);
}
}
}
}
实现图片缓慢展开功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。