android学习笔记34——ClipDrawable资源
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资源的更多相关文章
- android学习笔记37——Menu资源
Menu菜单资源 android应用推荐使用XML来定义菜单,其可提供更好的解耦方式. 菜单资源通常位于res/menu文件夹下,其菜单根元素为<menu.../>,menu元素下可包含子 ...
- android学习笔记35——AnimationDrawable资源
AnimationDrawable资源 AnimationDrawable,代表一个动画. android既支持传统的逐帧动画(类似于电影方式,一张图片一张图片的切换),也支持通过平移.变换计算出来的 ...
- Android学习笔记36:使用SQLite方式存储数据
在Android中一共提供了5种数据存储方式,分别为: (1)Files:通过FileInputStream和FileOutputStream对文件进行操作.具体使用方法可以参阅博文<Andro ...
- 【转】Pro Android学习笔记(四):了解Android资源(下)
处理任意的XML文件 自定义的xml文件放置在res/xml/下,可以通过R.xml.file_name来获取一个XMLResourceParser对象.下面是xml文件的例子: <rootna ...
- 【转】Pro Android学习笔记(三):了解Android资源(上)
在Android开发中,资源包括文件或者值,它们和执行应用捆绑,无需在源代码中写死,因此我们可以改变或替换他们,而无需对应用重新编译. 了解资源构成 参考阅读Android学习笔记(三八):资源res ...
- Android学习笔记之Activity详解
1 理解Activity Activity就是一个包含应用程序界面的窗口,是Android四大组件之一.一个应用程序可以包含零个或多个Activity.一个Activity的生命周期是指从屏幕上显示那 ...
- Pro Android学习笔记 ActionBar(1):Home图标区
Pro Android学习笔记(四八):ActionBar(1):Home图标区 2013年03月10日 ⁄ 综合 ⁄ 共 3256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 ActionBar在A ...
- 【转】 Pro Android学习笔记(七十):HTTP服务(4):SOAP/JSON/XML、异常
目录(?)[-] SOAP JSON和XMLPullParser Exception处理 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件,转载须注明出处:http://blog. ...
- 【转】 Pro Android学习笔记(五六):配置变化
目录(?)[-] Activity的destorycreate过程 Fragment的destorycreate过程 onSaveInstanceState saveFragmentInstanceS ...
随机推荐
- 如何用 freebayes call SNP
1,软件介绍 FreeBayes is a Bayesian genetic variant detector designed to find small polymorphisms, specif ...
- python 函数性能分析
1 使用profile分析函数性能示例1, 以profile为例: import profile def profileTest(): Total =1; for i in range(10): To ...
- pstack使用和原理
前言: 最近小组在组织<<深入剖析Nginx>>的读书会, 里面作者提到了pstack这个工具. 之前写JAVA程序, 对jstack这个工具, 非常的喜欢, 觉得很有用. 于 ...
- c语言中函数的递归
题目:用递归法把一个整数转换成字符串输出. 比较下面两种方法的不同: putchar(n%10+'0')的位置不同,造成输出结果的不同. 方法一: #include <stdio.h> v ...
- linux中进程控制
1.进程标识 每个进程都有一个非负整型表示的唯一的进程ID.进程ID标识符总是唯一的. 虽然进程ID是唯一的,但某个ID被回收后,ID号是可以复用的. ID为0的进程通常是调度进程(其常常被称交换进 ...
- 作业:用HTML制作简历
代码为: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- hdu2647 拓扑序
题意:年终要给 n 个员工发奖金,每个人的起始金额是888,有些人觉得自己做的比另一个人好所以应该多得一些钱,问最少需要花多少钱,如果不能满足所有员工的要求,输出 -1 拓扑排序,从奖金少的向奖金多的 ...
- Linux-dd命令详解【转】
转自http://www.cnblogs.com/dkblog/archive/2009/09/18/1980715.html Linux-dd命令详解 dd 是 Linux/UNIX 下的一个非 ...
- 【C++11】30分钟了解C++11新特性
作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 什么是C++11 C++11是曾经被叫做C+ ...
- Entity Framework的核心 – EDM(Entity Data Model) 一
http://blog.csdn.net/wangyongxia921/article/details/42061695 一.EnityFramework EnityFramework的全程是ADO. ...