最近迷上进度条,使用进度条可以增强用户体验,让用户心里有个底,再无奈的等待中体会loading的乐趣。

记得以前优乐美的官网,进入主页加载资源,显示给用户看的就是,炫彩背景下,一个杯子里的奶茶随着加载进度慢慢加上来,这对于浏览网站的人来讲,等于一种享受,并不是难熬等待的时间,在等待的时间的时候,她们看到确实另一番景象而不是单纯的进度条。

百度手机浏览器的做法又不一样,用户打开一个网页的时候,在后台请求资源并渲染,前台界面就是产品的宣传,几张宣传图相互切换,大部分PC软件的安装过程也是如此,在用户等待的时候,向用户宣传自己,让眼睛不会过度疲劳和产生厌倦感。

好了,话不多少,今天我们看看手机QQ空间,点击一张图片,然后加载。我们看图说话。

这个图片类型的进度条是怎么做的呢。

首先,这肯定是继承一个进度条ProgressBar,那我们分析一下ProgressBar的构成,主题分格是圆形的还是条状的,背景background,进度前景progressDrawable。

好我们看一下进度条的xml布局。

<ProgressBar android:id="@+id/pb"
style="?android:attr/progressBarStyleHorizontal"
android:background="@drawable/progress_bg"
android:progressDrawable="@drawable/progress_vertical"
android:layout_width="100dp"
android:layout_height="80dp"/>

style定义了条状进度条,background设置进度条背景(这里我们可以把灰色的背景图放进去),progressDrawable设置进度前景(前景图可以放一张蓝色图)。

但是如果这样设置的话,会产生什么情况呢,进度条是从左边往右边进展的,问题就来了,我怎么把进度条的增长方向改为垂直向上呢?

我们看下ProgressBar布局源码,progress是一个layer-list文件。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item> <item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item> <item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ffffd300"
android:centerColor="#ffffb600"
android:centerY="0.75"
android:endColor="#ffffcb00"
android:angle="270"
/>
</shape>
</clip>
</item> </layer-list>

可以看到android:id/progress这项包含了一个clip标签,在这里就可以控制自增方向,clip发现有3个属性,clipOrientation, gravity, drawable。在clipOrientation设置为纵向,drawable设置为蓝色图就大功告成啦!

看下实际效果:

不错吧!

相关源码:

main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical" >
6
7 <TextView
8 android:layout_width="fill_parent"
9 android:layout_height="wrap_content"
10 android:text="@string/hello" />
11
12 <Button android:id="@+id/bt"
13 android:text="开始"
14 android:layout_width="fill_parent"
15 android:layout_height="wrap_content"/>
16
17 <ProgressBar android:id="@+id/pb"
18 style="?android:attr/progressBarStyleHorizontal"
19 android:background="@drawable/progress_bg"
20 android:progressDrawable="@drawable/progress_vertical"
21 android:layout_width="100dp"
22 android:layout_height="80dp"/>
23
24 </LinearLayout>
progress_vertical.xml
 1 <?xml version="1.0" encoding="utf-8"?>
2 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3 <!--
4 <item android:id="@android:id/background" >
5 <shape>
6 <corners android:radius="5dip" />
7 <gradient
8 android:startColor="#fff"
9 android:endColor="#f00"
10 android:angle="270"
11 />
12 </shape>
13 </item> -->
14
15
16 <item android:id="@android:id/progress" >
17 <clip android:clipOrientation="vertical"
18 android:gravity = "bottom"
19 android:drawable="@drawable/progress"
20 >
21 <!--
22
23
24 <shape >
25 <corners android:radius="5dip" />
26 <gradient
27 android:startColor="#ffffd300"
28 android:centerColor="#ffffb600"
29 android:centerX="0.75"
30 android:endColor="#ffffcb00"
31 android:angle="90"
32 />
33 </shape> -->
34 </clip>
35 </item>
36
37 </layer-list>
MainActivity.java
 1 package com.bvin.study.progress;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.os.Handler;
6 import android.os.Message;
7 import android.view.View;
8 import android.widget.Button;
9 import android.widget.ProgressBar;
10
11 public class MainActivity extends Activity {
12 /** Called when the activity is first created. */
13 ProgressBar pb ;
14 Handler handler = new Handler(){
15
16 @Override
17 public void handleMessage(Message msg) {
18 // TODO Auto-generated method stub
19 super.handleMessage(msg);
20 pb.setProgress(msg.what);
21 }
22
23
24
25 };
26 @Override
27 public void onCreate(Bundle savedInstanceState) {
28 super.onCreate(savedInstanceState);
29 setContentView(R.layout.main);
30 init();
31 }
32
33 void init(){
34 pb = (ProgressBar)findViewById(R.id.pb);
35 Button bt = (Button)findViewById(R.id.bt);
36 bt.setOnClickListener(new View.OnClickListener() {
37
38 @Override
39 public void onClick(View v) {
40 // TODO Auto-generated method stub
41
42 pb.incrementProgressBy(10);
43
44
45 }
46 });
47 }
48 }

以后还会更新其他应用的一些UI设计揭秘,敬请关注!

AndroidのUI设计研究(一)——自定义ProgressBar的更多相关文章

  1. 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面

    [Android UI设计与开发]第05期:引导界面(五)实现应用程序只启动一次引导界面 jingqing 发表于 2013-7-11 14:42:02 浏览(229501) 这篇文章算是对整个引导界 ...

  2. shape和selector是Android UI设计中经常用到的

    shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...

  3. Android UI设计

    Android UI设计--PopupWindow显示位置设置 摘要: 当点击某个按钮并弹出PopupWindow时,PopupWindow左下角默认与按钮对齐,但是如果PopupWindow是下图的 ...

  4. (转载)Android UI设计之AlertDialog弹窗控件

    Android UI设计之AlertDialog弹窗控件 作者:qq_27630169 字体:[增加 减小] 类型:转载 时间:2016-08-18我要评论 这篇文章主要为大家详细介绍了Android ...

  5. 详解 “Android UI”设计官方教程

    我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...

  6. 移动周报:十款最实用的Android UI设计工具

    上一周可以说是一个不断Mark周,从最实用的Android UI设计工具.免费移动应用测试框架推荐,到HTML5开发框架等等,各种开发工具.框架精彩丰呈,看得小伙伴们是不亦乐乎.当然,还有不容错过的M ...

  7. 【转】【Android UI设计与开发】之详解ActionBar的使用,androidactionbar

    原文网址:http://www.bkjia.com/Androidjc/895966.html [Android UI设计与开发]之详解ActionBar的使用,androidactionbar 详解 ...

  8. Android UI设计的基本元素有哪些

    在android app开发如火如荼的今天,如何让自己的App受人欢迎.如何增加app的下载量和使用量....成为很多android应用开发前,必须讨论的问题.而ui设计则是提升客户视觉体验度.提升下 ...

  9. Android UI设计中一些不错的示例及第三方控件

    1.二级ListView自定义布局ExpandableListView http://pan.baidu.com/s/1mhlJh12 密码:nhc2 2.ListView实现各种动画效果ListVi ...

随机推荐

  1. [jobdu]二进制中1的个数

    做法是n&(n-1).据说还有变态的查表法:http://www.cnblogs.com/graphics/archive/2010/06/21/1752421.html.最后,居然必须用sc ...

  2. 告别山寨数据线:USB Type-C加密认证出炉

    从去年苹果发布的MacBook首次采用USB Type-C接口开始,这一标准逐渐成为主流,许多旗舰手机慢慢地采用了这种接口.今日,非盈利机构USB开发者论坛(USB-IF)宣布了USB Type-C认 ...

  3. CPU Benchmarks

    http://www.cpubenchmark.net/high_end_cpus.html 非常清楚~~~

  4. 【Quick 3.3】资源脚本加密及热更新(一)脚本加密

    [Quick 3.3]资源脚本加密及热更新(一)脚本加密 注:本文基于Quick-cocos2dx-3.3版本编写 一.脚本加密 quick框架已经封装好加密模块,与加密有关的文件在引擎目录/quic ...

  5. 公司估值(贴现现金流量法DCF)

    创业公司总会遇到并购或者入股等情况,CEO需要了解一些公司估值的方法,本文主要介绍贴现现金流量估值方法,供大家参考: 中国资产评估协会要求:在对企业价值进行评估时,应分析收益法.市场法和资产基础法三种 ...

  6. Java实现人民币大写精讲

    想要实现人民币大写,在发票等场景中使用?? 1234.56显示为:壹仟贰佰叁拾肆元伍角陆分,那就往下看看吧! 本程序可以实现 0 到 9999 9999 9999.994 以内的人民币大写转换,精确到 ...

  7. Ubuntu 出现apt-get: Package has no installation candidate问题

    今天在安装软件的时候出现了Package has no installation candidate的问题,如: #  apt-get install <packagename> Read ...

  8. VMWare12 安装 OSX 10.10

    推荐电脑配置 1:Inter I5及以上 (A卡请自行百度大神解决方案) 必须开启CPU虚拟化:开机进入 BIOS ---> Intel Virtualization Technology--- ...

  9. BIOS与UEFI、MBR和GPT介绍

    操作步骤: UEFI是取代传统BIOS的,全称“统一的可扩展固件接口”.MBR则是传统的分区表类型,最大的缺点则是不支持容量大于2T的硬盘.GPT则弥补了MBR这个缺点,最大支持18EB的硬盘,是基于 ...

  10. 《C#并行编程高级教程》第3章 命令式任务并行 笔记

    Task的使用 var t1 = new Task(() => GenerateAESKeys());var t2 = new Task(() => GenerateMD5Hashes() ...