您的位置:首页 > 其它

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;

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: