Horizontal---ProgressBar
2015-06-08 18:05
447 查看
相当简单,直接贴
先看主界面布局activity_custom_progress_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center"> <Button android:text="自定义颜色进度条" android:id="@+id/color" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:text="自左向右的进度条" android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
ProgressBarMain
package com.example.progressdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class ProgressBarMain extends Activity implements OnClickListener { /** * 按钮点击进入自定义颜色的进度条页面 */ private Button color; /** * 按钮点击进入左方向进度条页面 */ private Button left; /** * 按钮点击进入右方向进度条页面 */ private Button right; /** * 按钮点击进入不定进度条页面 */ private Button indeter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_progress_main); initProperty(); } private void initProperty() { color = (Button) findViewById(R.id.color); left = (Button) findViewById(R.id.left); color.setOnClickListener(this); left.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.color: startActivity(new Intent(this, ProgressBar_Color.class)); break; case R.id.left: startActivity(new Intent(this, ProgressBar_Left.class)); break; default: break; } } }
接下来看ProgressBar_Color
package com.example.progressdemo; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.widget.ProgressBar; public class ProgressBar_Color extends Activity { private ProgressBar mColor = null; private int mCount = 0; private final int HANDLER_LEFT = 1; private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == HANDLER_LEFT) { finish(); } super.handleMessage(msg); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_progress_mypage_color); showIndeterDialog(); } private void showIndeterDialog() { mCount = 0; mColor = (ProgressBar) findViewById(R.id.progress_horizontal_color); mColor.setMax(100); mColor.setProgress(0); //)就是滚动条的当前值自动在最小到最大值之间来回移动,形成这样一个动画效果,这个只是告诉别人“我正在工作”,但不能提示工作进度到哪个阶段 mColor.setIndeterminate(false); new Thread() { public void run() { try { while (mCount <= 100) { mColor.setProgress(mCount++); Thread.sleep(100); } if (mCount > 100) { mHandler.sendEmptyMessage(HANDLER_LEFT); } } catch (Exception ex) { } } }.start(); } }
看activity_custom_progress_mypage_color.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" > <ProgressBar android:id="@+id/progress_horizontal_color" style="@style/progressBarHorizontal_color" android:layout_width="200dip" android:layout_height="10dip" android:max="100" android:progress="41" /> </LinearLayout>styles.xml
<style name="progressBarHorizontal_color" parent="android:Widget.ProgressBar.Horizontal"> <item name="android:indeterminateOnly">false</item> <item name="android:progressDrawable">@drawable/progress_color_horizontal</item> <item name="android:minHeight">5dip</item> <item name="android:maxHeight">5dip</item> </style>
接下来看drawable
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 最下边层 angle表示方向角度,0为从左向又,然后逆时针转,90时候表示从下往上 --> <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <gradient android:angle="90" android:centerColor="#ff5a5d5a" android:centerY="0.75" android:endColor="#ff747674" android:startColor="#ff9d9e9d" /> </shape> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="90" android:centerColor="#ffBBFFBB" android:centerY="0.75" android:endColor="#ff00DB00" android:startColor="#ff00DB00" /> </shape> </clip> </item> </layer-list>
----------------------------------------------第一个效果实现了,下面是同样效果的第二种方法----------------------------------------------------
<style name="progressBarHorizontal" parent="android:Widget.ProgressBar.Horizontal"> <item name="android:indeterminateOnly">false</item> <item name="android:progressDrawable">@drawable/progress_horizontal</item> <item name="android:minHeight">5dip</item> <item name="android:maxHeight">5dip</item> </style>
接下来看drawable
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background" android:drawable="@drawable/progressbar_back"> </item> <item android:id="@android:id/progress" android:drawable="@drawable/progressbar_indeter1"> </item> </layer-list>
相关文章推荐
- [bootstrap] 修改字体
- Dispose的重写
- 《Linux内核设计与实现》读书笔记之进程地址空间
- ffmpeg学习(二) 通过rtsp获取H264裸流并保存到mp4文件
- linux命令
- [缓存]Linux系统memcached的安装
- 玩转iOS开发 - Runloop 详解
- 解决Secure CRT不能显示中文的BUG
- Ceiling分页存储过程
- 个人热点
- LeetCode | Valid Palindrome
- file_put_contents之用途
- Android 环境变量配置(Mac)
- 知识共享 - creative commons
- Android 环境变量配置(Mac)
- 新建一个android项目,同时出现appcompat_v7项目。
- Android 线性布局(LinearLayout)相关官方文档 - 指南部分
- Java-归并排序
- Zip Utils - clean, elegant, simple, C++/Win32
- 一 数据库基本知识