• Andorid Clip 实现自定义的进度条效果实例


    Android该系统提供了一个水平进度条为我们展现了运行使用进展情况,水平进度条显示用于运行进度Clip Drawable技术
    下面我们通过一个具体的例子来说明Clip Drawable使用。

    还有我们要注意知识:

    Clip0,此时是所有裁剪,图片看不见;
    当级别为10000时,不裁剪图片,图片所有可见

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

          

    新建一个名称为: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);
    		}
    
    	}
    }
    


    程序中用的资源图片:



    源代码

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

  • 相关阅读:
    懒加载——实现原理
    html5shiv.js和respond.min.js
    点击app分享链接,js判断手机是否安装某款app,有就尝试打开,没有就下载
    ajax获取后台数据渲染(整片文章不分段落)解决方案,要使用htmL方式输出
    +-下拉菜单
    html 中a标签的问题(无反应,跳转,调用方法)
    js中两种定时器,setTimeout和setInterval的区别
    chrome 调试进入 paused in debugger 状态解决办法
    mybatis-plus 获取新增id
    linux unzip和zip
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4612731.html
Copyright © 2020-2023  润新知