AndroidのUI设计研究(一)——自定义ProgressBar
最近迷上进度条,使用进度条可以增强用户体验,让用户心里有个底,再无奈的等待中体会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的更多相关文章
- 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面
[Android UI设计与开发]第05期:引导界面(五)实现应用程序只启动一次引导界面 jingqing 发表于 2013-7-11 14:42:02 浏览(229501) 这篇文章算是对整个引导界 ...
- shape和selector是Android UI设计中经常用到的
shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...
- Android UI设计
Android UI设计--PopupWindow显示位置设置 摘要: 当点击某个按钮并弹出PopupWindow时,PopupWindow左下角默认与按钮对齐,但是如果PopupWindow是下图的 ...
- (转载)Android UI设计之AlertDialog弹窗控件
Android UI设计之AlertDialog弹窗控件 作者:qq_27630169 字体:[增加 减小] 类型:转载 时间:2016-08-18我要评论 这篇文章主要为大家详细介绍了Android ...
- 详解 “Android UI”设计官方教程
我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...
- 移动周报:十款最实用的Android UI设计工具
上一周可以说是一个不断Mark周,从最实用的Android UI设计工具.免费移动应用测试框架推荐,到HTML5开发框架等等,各种开发工具.框架精彩丰呈,看得小伙伴们是不亦乐乎.当然,还有不容错过的M ...
- 【转】【Android UI设计与开发】之详解ActionBar的使用,androidactionbar
原文网址:http://www.bkjia.com/Androidjc/895966.html [Android UI设计与开发]之详解ActionBar的使用,androidactionbar 详解 ...
- Android UI设计的基本元素有哪些
在android app开发如火如荼的今天,如何让自己的App受人欢迎.如何增加app的下载量和使用量....成为很多android应用开发前,必须讨论的问题.而ui设计则是提升客户视觉体验度.提升下 ...
- Android UI设计中一些不错的示例及第三方控件
1.二级ListView自定义布局ExpandableListView http://pan.baidu.com/s/1mhlJh12 密码:nhc2 2.ListView实现各种动画效果ListVi ...
随机推荐
- 【Linux安全】文件或目录权限设置
实例演示: 要求:新建文件夹,名称为secure,要求改文件夹只能被创建者deadmin以及与deadmin同组用户进行读.写.执行的权限, 其他用户均只有读的权限. 查看 一下secure原本的权限 ...
- RxJava开发精要1-从.NET到RxJava
原文出自<RxJava Essentials> 原文作者 : Ivan Morgillo 译文出自 : 开发技术前线 www.devtf.cn 转载声明: 本译文已授权开发者头条享有独家转 ...
- CSS属性一览
CSS 属性 CSS 属性组: 动画 背景 边框和轮廓 盒(框) 颜色 内容分页媒体 定位 可伸缩框 字体 生成内容 网格 超链接 行框 列表 外边距 Marquee 多列 内边距 分页媒体 定位 打 ...
- jdbcTemplate 获取数据表结构
jdbcTemplate 操作方法 /** *1.方法一: */ String sql = "select * from "+ tableName; //RowCountCallb ...
- MFC VS2005 添加Override 和 Message
VS2005 1.Overrides OnInitDialog() 在Class View选中 这个类,然后properties中点Message 旁边的Overrides, 添加OnInitDial ...
- 谈谈分布式事务之二:基于DTC的分布式事务管理模型[下篇]
[续上篇] 当基于LTM或者KTM的事务提升到基于DTC的分布式事务后,DTC成为了本机所有事务型资源管理器的管理者:此外,当一个事务型操作超出了本机的范 围,出现了跨机器的调用后,本机的DTC需要于 ...
- nginx根据域名做http,https分发
omcat端口:8080 做好虚拟主机 参照我的另一篇文章nginx端口:80 根据域名分派 在conf/nginx.conf中的http中增加 include www.huozhe.com.conf ...
- HDU 5651 xiaoxin juju needs help 水题一发
分析:求一下组合数 首先,如果不止一个字符出现的次数为奇数,则结果为0. 否则,我们把每个字符出现次数除2,也就是考虑一半的情况. 那么结果就是这个可重复集合的排列数了. fact(n)/fact(a ...
- 超大型 LED 显示屏
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11574&courseid=0 题目 E. 超大型 L ...
- css网站导航-菜单
一个简单的网站导航效果: 效果案例:查看演示 css: ;;;} body{font-family: arial, 宋体, serif;font-size: 12px;} .menu{width:11 ...