ClipDrawable

ClipDrawable代表从其他位图上截取一个“图片片段”

在XML文件中定义ClipDrawable对象使用<clip.../>元素,该元素的语法为:

以上语法格式中可指定如下三个属性:

1.android:drawable:指定截取的源Drawable对象

2.android:clipOrientaton:指定截取方向,可设置水平或垂直截取

3.android:gravity:指定截取时的对齐方式

注:使用ClipDrawable对象是可调用setLevel(int levle)方法设置截取的区域大小,当level为0时,截取的图片片段为空;当level为10000时,截取整张图片。

实例如下:徐徐展开的风景

注意:实际开发中,可采用该种方式完成进度显示控制。

资源文件==》drawable文件夹下
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="horizontal"
android:drawable="@drawable/people"
android:gravity="center" > </clip> 布局文件==》
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity" > <ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myclip" /> </LinearLayout> 代码实现==》
package com.example.myclipdrawable; import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ClipDrawable;
import android.view.Menu;
import android.widget.ImageView; @SuppressLint("HandlerLeak")
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ImageView img = (ImageView) this.findViewById(R.id.image);
final ClipDrawable drawable = (ClipDrawable) img.getDrawable();
final Handler hanler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
if (msg.what == 1)
{
int value=drawable.getLevel() + 200;
drawable.setLevel(value);
}
}
}; final Timer timer = new Timer();
timer.schedule(new TimerTask()
{
@Override
public void run()
{
Message msg = new Message();
msg.what = 1;
hanler.sendMessage(msg);
// 取消定时器
if (drawable.getLevel() >= 10000)
{
timer.cancel();
}
}
}, 0, 300);
} @Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }

运行效果:随着时间的变化,图片逐渐被截取完成

       

android学习笔记34——ClipDrawable资源的更多相关文章

  1. android学习笔记37——Menu资源

    Menu菜单资源 android应用推荐使用XML来定义菜单,其可提供更好的解耦方式. 菜单资源通常位于res/menu文件夹下,其菜单根元素为<menu.../>,menu元素下可包含子 ...

  2. android学习笔记35——AnimationDrawable资源

    AnimationDrawable资源 AnimationDrawable,代表一个动画. android既支持传统的逐帧动画(类似于电影方式,一张图片一张图片的切换),也支持通过平移.变换计算出来的 ...

  3. Android学习笔记36:使用SQLite方式存储数据

    在Android中一共提供了5种数据存储方式,分别为: (1)Files:通过FileInputStream和FileOutputStream对文件进行操作.具体使用方法可以参阅博文<Andro ...

  4. 【转】Pro Android学习笔记(四):了解Android资源(下)

    处理任意的XML文件 自定义的xml文件放置在res/xml/下,可以通过R.xml.file_name来获取一个XMLResourceParser对象.下面是xml文件的例子: <rootna ...

  5. 【转】Pro Android学习笔记(三):了解Android资源(上)

    在Android开发中,资源包括文件或者值,它们和执行应用捆绑,无需在源代码中写死,因此我们可以改变或替换他们,而无需对应用重新编译. 了解资源构成 参考阅读Android学习笔记(三八):资源res ...

  6. Android学习笔记之Activity详解

    1 理解Activity Activity就是一个包含应用程序界面的窗口,是Android四大组件之一.一个应用程序可以包含零个或多个Activity.一个Activity的生命周期是指从屏幕上显示那 ...

  7. Pro Android学习笔记 ActionBar(1):Home图标区

     Pro Android学习笔记(四八):ActionBar(1):Home图标区 2013年03月10日 ⁄ 综合 ⁄ 共 3256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 ActionBar在A ...

  8. 【转】 Pro Android学习笔记(七十):HTTP服务(4):SOAP/JSON/XML、异常

    目录(?)[-] SOAP JSON和XMLPullParser Exception处理 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件,转载须注明出处:http://blog. ...

  9. 【转】 Pro Android学习笔记(五六):配置变化

    目录(?)[-] Activity的destorycreate过程 Fragment的destorycreate过程 onSaveInstanceState saveFragmentInstanceS ...

随机推荐

  1. sticky bit

    • Sticky Bit这个Sticky Bit当前只针对目录有效,对文件没有效果.SBit对目录的作用是:“在具有SBit的目录下,用户若在该目录下具有w及x权限,则当用户在该目录下建立文件或目录时 ...

  2. Single Number-C++中的异或

    Single Number Given an array of integers, every element appears twice except for one. Find that sing ...

  3. codeforce Group Photo 2 (online mirror version)

    题目大意: 有n个矩形在地上排成一列,不可重叠,已知他们的宽度w和高度h,现在使至多[n / 2]个矩形旋转90度,问最后可以用多小的矩形恰好覆盖这n个矩形,求满足条件的最小矩形面积. n, w, h ...

  4. spring学习笔记---第三方SDK(Rest API)和Jaskson的巧用

    前言: 其实我以前一直不懂电商, 以及电商中所涉及的业务概念. 对于SKU等名词, 觉得有些玄乎. 对其背后的数据模型, 也有莫名的未知恐惧感: 庞大而理不清头绪. 不过最近有机会接触了微商(有赞), ...

  5. Jquery.KinSlideshow图片轮播插件

    KinSlideshow无缝滑动幻灯片jquery特效代码Jquery幻灯片特效jquery.KinSlideshow-1.1.js 兼容IE6/IE7/IE8/IE9,FireFox,Chrome* ...

  6. 268. Missing Number

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  7. 334. Increasing Triplet Subsequence

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  8. poj 2299 树状数组求逆序对数+离散化

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 54883   Accepted: 20184 ...

  9. ZOJ 1029 Moving Tables

    原题链接 题目大意:走廊两边排列了400个房间,要在两个房间之间搬桌子.搬桌子的时候会占用一部分走廊,有冲突的话要回避.求最快搬完的时间. 解法:开辟一个数组,每占用一段走廊,就把相应的房间号的元素加 ...

  10. c#部分---用结构体的题目- //请输入班级人数,输入每个人的学号,姓名,和语文分数、数学分数和英语分数(要求使用结构体)

    //请输入班级人数,输入每个人的学号,姓名,和语文分数.数学分数和英语分数(要求使用结构体), //求班级里两个语文分数是最高分的学生的所有信息:数学分数是最高分的两个学生的所有信息:英语平均分 建立 ...