ProgressBar长方形进度条,item背景当进度条
2015-07-28 13:51
225 查看
效果图如下:
项目地址:http://download.csdn.net/detail/a876434758/8939681
首先要确定进度条的样式: style.xml
<!-- progressBar宽条样式 -->
<style name="tallerBarStyle" parent="@android:style/Widget.SeekBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
<item name="android:minHeight">40dip</item>
<item name="android:maxHeight">60dip</item>
</style>
<style name="anse">#cccccc</style>
<style name="anse1">#48A9EB</style>
<style name="anse2">#87F141</style>
进度条的背景色和前景色: 放在drawable 文件夹下progressbarb.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<corners android:radius="0dip" />
//背景色
<solid android:color="#CCCCCC" />
</shape>
</item>
<!--一级进度条的颜色,也可以直接替换成图片-->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="0dip" />
<solid android:color="#55C2DD" />
</shape>
</clip>
</item>
</layer-list>
接下来是布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
>
<ProgressBar
android:id="@+id/progressBar1"
style="@style/tallerBarStyle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:max="100"
android:progressDrawable="@drawable/progressbarb"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="昵称:会飞的蜗牛"
android:textSize="20sp"
/>
</RelativeLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
源代码activity
package com.example.trustmobi_mixin_test;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends Activity implements Runnable{
private ProgressBar progressBar1 = null;
private Button button1 = null;
Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
//可以让它未运行前隐藏
//progressBar1.setVisibility(View.VISIBLE);
Thread thread = new Thread(MainActivity.this);
thread.start();
}
});
handler = new Handler() {
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
//运行完毕后隐藏
// progressBar1.setVisibility(View.INVISIBLE);
}
};
}
public void run() {
// TODO Auto-generated method stub
int sum = 0;
for (;;) {
progressBar1.setProgress(sum);
// progressBar1.setSecondaryProgress(sum);
sum += 10;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (progressBar1.getProgress() == progressBar1.getMax()) {
handler.sendMessage(handler.obtainMessage());
System.out.println("ggggggggggggg");
break;
}
}
}
}
项目地址:http://download.csdn.net/detail/a876434758/8939681
首先要确定进度条的样式: style.xml
<!-- progressBar宽条样式 -->
<style name="tallerBarStyle" parent="@android:style/Widget.SeekBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
<item name="android:minHeight">40dip</item>
<item name="android:maxHeight">60dip</item>
</style>
<style name="anse">#cccccc</style>
<style name="anse1">#48A9EB</style>
<style name="anse2">#87F141</style>
进度条的背景色和前景色: 放在drawable 文件夹下progressbarb.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<corners android:radius="0dip" />
//背景色
<solid android:color="#CCCCCC" />
</shape>
</item>
<!--一级进度条的颜色,也可以直接替换成图片-->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="0dip" />
<solid android:color="#55C2DD" />
</shape>
</clip>
</item>
</layer-list>
接下来是布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
>
<ProgressBar
android:id="@+id/progressBar1"
style="@style/tallerBarStyle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:max="100"
android:progressDrawable="@drawable/progressbarb"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="昵称:会飞的蜗牛"
android:textSize="20sp"
/>
</RelativeLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
源代码activity
package com.example.trustmobi_mixin_test;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends Activity implements Runnable{
private ProgressBar progressBar1 = null;
private Button button1 = null;
Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
//可以让它未运行前隐藏
//progressBar1.setVisibility(View.VISIBLE);
Thread thread = new Thread(MainActivity.this);
thread.start();
}
});
handler = new Handler() {
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
//运行完毕后隐藏
// progressBar1.setVisibility(View.INVISIBLE);
}
};
}
public void run() {
// TODO Auto-generated method stub
int sum = 0;
for (;;) {
progressBar1.setProgress(sum);
// progressBar1.setSecondaryProgress(sum);
sum += 10;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (progressBar1.getProgress() == progressBar1.getMax()) {
handler.sendMessage(handler.obtainMessage());
System.out.println("ggggggggggggg");
break;
}
}
}
}
相关文章推荐
- Android开发——使用Jword生成本地word文档
- vi文件搜索某个关键字
- (转)Angular中的拦截器Interceptor
- android常用UI使用案例:AutoCompleteTextView
- MyEclipse 安装目录下找不到Common目录
- linux新手入门常用文件以及系统操作方法
- tomcat内存溢出与调优
- go语言条件语句 if else
- Java JDBC连接数据库
- 黑马程序员--循环语句
- js获取随机数
- ContextMenu上下文菜单
- 信息异步处理,关于handle和thread交互信息,只能更改一个textview的问题原因分析
- 理解 Linux CPU 负载 1分5分15分
- eclipse 设置在windows 资源管理器中打开快捷键
- Android技术点滴记录
- Linux64位操作系统(CentOS6.6)上如何编译spark1.3
- zTree实现删除某个父节点后删除其下所有节点
- 记录几点在开发中遇到的问题 2015-7-28 (会更新)
- App上架一天后无法查找到,什么原因呢?