android 进度条裁剪,Andorid Clip 实现自定义的进度条效果实例

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

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

还有我们要注意知识:

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

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

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

509e43af66ad21d438550277255b04bf.png   

fdc6d0cde6c91d27cf8d8d3343499c1a.png 

l1dym80Ade

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

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

程序结构文件夹:

4f8eb407fd5f5ff026fbbbd2c37e8e40.png

activity_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/gril_img"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/clip"

android:contentDescription="@string/app_name"

/>

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"/>

clip.xml

android:drawable="@drawable/girl"

android:clipOrientation="horizontal"

android:gravity="left"

>

strings.xml

ClipDrawable

Hello world!

Settings

clip

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);

}

}

}

程序中用的资源图片:

l1dym80Ade

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值