android 进度条的ui固定不动,Android UI控件之ProgressBar进度条

我们知道在所有的界面UI中进度条无疑是非常重要的一个,因为它可以给用户一个较为清晰的视觉效果:就是用户的操作的完成情况.这不是简单的完成与未完成,而是以一个进度的方式展示给用户的交互性更强了。

对于Android系统中的进度条如何使用呢?下一是简单的实现,并未做相关的美化处理。

依照惯例,先上效果图:

第一张:

201712190943356.png

第二张:

201712190943357.png

其中两个原型的进度条并未做任何的处理,水平进度条利用线程使之不停地增加减少。

具体实现首先看布局文件:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="简单进度条的展示"

android:layout_gravity="center_horizontal"/>

android:id="@+id/progressBar1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

/>

android:id="@+id/progressBar2"

style="?android:attr/progressBarStyleLarge"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"/>

android:id="@+id/progressBar3"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:max="100"

android:minWidth="180dip"

android:minHeight="40dip"

/>

之后是MainActivity

package com.kiritor.ui_progressbar;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.widget.ProgressBar;

public class MainActivity extends Activity implements Runnable {

private ProgressBar bar = null;

private Thread thread = null;// 声明一个线程

private boolean stateChange;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

bar = (ProgressBar) findViewById(R.id.progressBar3);

thread = new Thread(this);

thread.start();

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

@Override

public void run() {

while (true) {

int current = bar.getProgress();// 得到当前进度值

int currentMax = bar.getMax();// 得到进度条的最大进度值

//int secCurrent = bar.getSecondaryProgress();// 得到底层当前进度值

// 以下代码实现进度值越来越大,越来越小的一个动态效果

if (stateChange == false) {

if (current >= currentMax) {

stateChange = true;

} else {

// 设置进度值

bar.setProgress(current + 1);

// 设置底层进度值

bar.setSecondaryProgress(current + 1);

}

} else {

if (current <= 0) {

stateChange = false;

} else {

bar.setProgress(current - 1);

bar.setSecondaryProgress(current - 1);

}

}

try {

Thread.sleep(50);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

以上就是进度条的简单的用法,之后笔者会实现一些“特别”进度条,漂亮的,另类的!代码较为简单就不给源码了Over!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值