ClipDrawable代表从其它位图上截取一个"图片片段",XML中的根元素为<clip.../>,截取的方向由clipOrientation控制

<?xml version="1.0" encoding="utf-8"?>
<clip
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:clipOrientation=["horizontal" | "vertical"]
android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
"fill_vertical" | "center_horizontal" | "fill_horizontal" |
"center" | "fill" | "clip_vertical" | "clip_horizontal"] />

android:clipOrientation有两个属性,默认为horizontal
android:gravity有两个属性,默认为left

使用时可以用ClipDrawable的setLevel(int level)方法来设置截取图片的区域大小,当level为0,就是空;为10000时,截取整个图片。

下面是通过这个对象来实现图片缓缓展开的效果。

转自:http://blog.csdn.net/jiaruihua_blog/article/details/12276215

    

思路:

1.在xml中写clip标签,在drawable中放入一个图片

2.在布局中放一个ImageView,src选择这个xml文件

3.在代码中用Imageview的findViewById()找到imageview对象

4.通过 final ClipDrawable drawable = (ClipDrawable)imageview.getDrawable(); 得到ClipDrawable对象

5.通过Timer和Handler结合来改变截取图片的大小,这里要通过setLevel()来做

6.当ClipDrawable.getLevel() >= 10000时结束截取,因为这时已经截取了全部图片

代码:

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/gril"
android:clipOrientation="horizontal"
android:gravity="center">
</clip>

layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" > <ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitStart"
android:src="@drawable/clip_style"
/> </RelativeLayout>

java

package com.example.clipdrawable; 

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; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ImageView imageView = (ImageView) findViewById(R.id.image);
//获取图片所显示的ClipDrawable对象
final ClipDrawable drawable = (ClipDrawable) imageView.getDrawable();
final Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
if (msg.what==0x123) {
/**setlevel()设置图片截取的大小
* 修改ClipDrawable的level值,level值为0--10000;
* 0:截取图片大小为空白,10000:截取图片为整张图片;
*/
drawable.setLevel(drawable.getLevel()+200);
}
} };
final Timer timer = new Timer();
timer.schedule(new TimerTask() { @Override
public void run() {
// TODO Auto-generated method stub
Message msg = new Message();
msg.what = 0x123;
handler.sendMessage(msg);
if (drawable.getLevel()>=10000) {
timer.cancel();
}
}
}, 0,300);
}
}

详细参考:

http://blog.csdn.net/lee576/article/details/7827676

http://blog.csdn.net/jiaruihua_blog/article/details/12276215

ClipDrawable属性介绍的更多相关文章

  1. DIV+CSS布局中主要CSS属性介绍

    Float: Float属性是DIV+CSS布局中最基本也是最常用的属性,用于实现多列功能,我们知道<div>标签默认一行只能显示一个,而使用Float属性可以实现一行显示多个div的功能 ...

  2. Android使用Drawable资源之使用ClipDrawable资源 实现进入条

    以前我自定义的进度条(就是咱们现在工程中用的)是从android的源码中扒出来的一个XML,然后把里面的图片给替换了.一直不知道它的具体原理是什么. 今天得空研究了一下,发现它的原理其实就是用的and ...

  3. ClipDrawable 实现图片渐变现实

    clip.xml <?xml version="1.0" encoding="utf-8"?><clip xmlns:android=&quo ...

  4. location.hash属性介绍

    location.hash属性介绍 例如URL: http://wwww.a.com/index#rhythmk 通过location.hash 我们将获取到 #rhythmk. 默认浏览器会滚动至i ...

  5. Autocomplete:属性介绍、firefox中文支持问题

    如有问题,请前往 http://www.cnblogs.com/dreamowneryong/p/4953911.html 原文评论交流 一,属性介绍 * minChars (Number) 在触发a ...

  6. android学习笔记34——ClipDrawable资源

    ClipDrawable ClipDrawable代表从其他位图上截取一个“图片片段” 在XML文件中定义ClipDrawable对象使用<clip.../>元素,该元素的语法为: 以上语 ...

  7. Intent的属性介绍

    在Android系统的设计中有四大组件:Activity,Service,BroadcastReceiver,ContentProvider.Intent可以被应用于ContentProvider之外 ...

  8. RelativeLayout常用属性介绍

    RelativeLayout常用属性介绍 转自: http://www.douban.com/note/97496783/ 下面介绍一下RelativeLayout用到的一些重要的属性: 第一类:属性 ...

  9. ClipDrawable 资源

    ClipDrawable 代表从其他位图上截取的一个“图片片段”. 示例: main.xml <?xml version="1.0" encoding="utf-8 ...

随机推荐

  1. .NetCore Cap 注册 Consul 服务发现

    注册服务发现 需要使用Cap中的UseDiscovery方法 具体用法如下 var capConsulConfig = Configuration.GetSection("CapConsul ...

  2. norbert-构建服务器集群感知的 Java 应用程序

    http://www.ibm.com/developerworks/cn/java/j-zookeeper/index.html

  3. Axios 是一个基于 promise 的 HTTP 库

    Axios 是一个基于 promise 的 HTTP 库 vue项目中关于axios的简单使用 axios介绍 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.j ...

  4. Eclipse 之开发环境的常用配置

    一.Java智能提示 (1). 打开Eclipse,选择打开" Window - Preferences". (2). 在目录树上选择"Java-Editor-Conte ...

  5. Codeforces 1028E Restore Array 构造

    我发现我构造题真的不会写, 想了好久才想出来.. 我们先把n = 2, 所有数字相等, 所有数字等于0的都特判掉. 找到一个b[ i ] > b[ i - 1 ]的位置把它移到最后一个位置, 并 ...

  6. tail -f 与 tail -F的区别

    使用tail -f监控某个文件,将在另一个窗口将该文件删除后,然后再新创建,那么我们会发现tail -f的监制失效了.而使用tail -F会再次进行监控.

  7. 【LeetCode】170. Two Sum III – Data structure design

    Difficulty:easy  More:[目录]LeetCode Java实现 Description Design and implement a TwoSum class. It should ...

  8. Noip2018游记——AFO

    本来Day 0和Day 1写得挺轻松的,结果没想到Day 2是这样的画风...心情逐渐沉重... Day 0 白天的时候颓的一批,上午考的信心赛还打错了一个字母然后$100pts\rightarrow ...

  9. catalan数的新理解

    catalan数的新理解h[5]==h[4][0]+h[3][1]+h[2][2]+h[1][3]+h[0][4];对于这种递推式就是catalan数

  10. HTML中元素的定位方式

    初中物理就学过,位置是相对的,要有参照物,因此,所有定位都是相对参照物的定位. position 属性: 规定元素的定位类型,该属性的可选值有static.relative.absolute.fixe ...