Android该系统提供了一个水平进度条为我们展现了运行使用进展情况,水平进度条显示用于运行进度Clip Drawable技术

下面我们通过一个具体的例子来说明Clip Drawable使用。

还有我们要注意知识:

Clip0,此时是所有裁剪,图片看不见;

当级别为10000时,不裁剪图片,图片所有可见

程序执行结果:第一张为初始界面,第二张为点击5次界面,第三张为点击10的界面

    
 

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3F0ZGR0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="200" height="300" alt="">

新建一个名称为:Clip Drawable的Android project。

程序结构文件夹:

activity_main.xml

<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"> <ImageView
android:id="@+id/gril_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/clip"
android:contentDescription="@string/app_name"
/> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Clip"
android:onClick="change"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>

clip.xml

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

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">ClipDrawable</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="Clip">clip</string>
</resources>

MainActivity.java

package com.shen.clipdrawable;

import android.support.v7.app.ActionBarActivity;
import android.graphics.drawable.ClipDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView; public class MainActivity extends ActionBarActivity { private ImageView imageView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取Imageview控件
imageView = (ImageView) findViewById(R.id.gril_img);
} @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;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} public void change(View v) {
// 获得ClipDrawable对象
ClipDrawable clipDrawable = (ClipDrawable) imageView.getBackground();
// 设置裁剪级别,Clip类型的图片默认裁剪级别为0。此时是所有裁剪。图片看不见;
// 当级别为10000时。不裁剪图片,图片所有可见
// 当所有显示后。设置不可见
if (10000 == clipDrawable.getLevel()) {
clipDrawable.setLevel(0);
}
else {
clipDrawable.setLevel(clipDrawable.getLevel() + 1000);
} }
}

程序中用的资源图片:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3F0ZGR0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

源代码

版权声明:本文博客原创文章,博客,未经同意,不得转载。

最新文章

  1. angularJS(3)
  2. Zookeeper集群的安装和使用
  3. PHP 数组的遍历的几种方式(以及foreach与for/while+each效率的比较)
  4. BZOJ3992: [SDOI2015]序列统计
  5. Hadoop学习之自定义二次排序
  6. 进入MFC讲坛的前言(一)
  7. php_PHP与Mysql的连接
  8. 基于tomcat为了应对高并发模型实现webserver
  9. JavaScript修改Canvas图片
  10. 计算字符串中每种字符出现的次数[Dictionary&lt;char,int&gt;泛型集合用法]
  11. 洛谷P1123取数游戏题解
  12. vim编辑
  13. nginx代理配置 配置中的静态资源配置,root 和 alias的区别
  14. Django rest framework集成微博第三方登录
  15. Scala之隐式转换
  16. VC_窗口exe_printf信息
  17. 查验身份证 (15 分) 一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:
  18. asp.net控件拖不动。控件错误
  19. springboot 整合 mongodb实现 批量更新数据
  20. 刘昕鑫 C# 特性详解

热门文章

  1. ORA-01403: no data found
  2. 设置HTTP代理
  3. Session for Tornado(Redis) - 代码分享
  4. POJ 3892 RSA Factorization
  5. spring中bean的一些知识点
  6. 【实战】静默安装-oracle 11.2.0.3 on centos 5.10
  7. OpenCV Python教程(3、直方图的计算与显示)
  8. jquery ajax局部加载方法介绍
  9. [置顶] ※数据结构※→☆线性表结构(queue)☆============队列 顺序存储结构(queue sequence)(八)
  10. [概念] js的函数节流和throttle和debounce详解