A. android自定义环形进度条怎么自由控制进度条的消失与隐藏
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetoothmeter);
mhandler = new Handler();
//通过mSearcheHandler更新UI
mSearchHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==0){
//改变环形进度条的进度
mCircleProcessBar.setProgress(mcnt);
mcnt+=1;
if(MCNT_MAX<=mcnt){
mCircleProcessBar.setVisibility(View.GONE);
}
}
}
};
mBlueService = BluetoothLeService.getInstance();
initView();
initEvent();
}
private void initEvent()
{
mImgBtnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//搜索
mbtnSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Prepare list view and initiate scanning
if (m_devicelistadapter != null) {
m_devicelistadapter.clear();
m_devicelistadapter.notifyDataSetChanged();
}
startScan();
//设置圆环进度条的出现时间(秒)
new TimerDelay(mSearchHandler).setDelayTime(CIRCLE_APPARE_TIME,mCircleProcessBar);
mcnt=1;
}
});
}
B. android studio怎么把进度条的值取出来
本文实例为大家分享了Android Studio实现进度条效果的具体代码,供大家参考,具体内容如下:
xml代码
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ProgressBarActivity">
android:id="@+id/pb_determinate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal"
android:backgroundTint="@color/purple_200"
android:progress="25"
android:max="100"
android:layout_centerVertical="true"
/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ProgressBar"
android:textSize="28sp"
android:gravity="center"
android:layout_below="@+id/pb_determinate"
C. android编程里如何使用按钮来增加和减少进度条的进度
java">//这个是增加的,把这看懂,减的也就会了
packagecom.example.progressbardemo;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.ProgressBar;
{
privateProgressBarone;
privateButtonbutton;
privateinti=0;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
one=(ProgressBar)findViewById(R.id.progressBar2);
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
if(i==0){
one.setVisibility(View.VISIBLE);
}
elseif(i<one.getMax())
{
one.setProgress(i);
}
else
{
one.setVisibility(View.GONE);
i=0;
}
i+=5;
}
});
}
}
D. 安卓怎么在在对话框中 搞一个进度条
方法/步骤:
单击按钮,弹出对话框,对话框中有进度条!
下面 来实现这个功能了
新建一个android工程,定义好xml 只需要一个button就可以了
在MainAtvity中,定义
ProgressDialog m_pDialog;
创建单击响应事件
在OncliView中可以
m_pDialog = new ProgressDialog(MainActivity.this);
// 设置进度条风格,风格为圆形,旋转的
m_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// 设置ProgressDialog 标题
m_pDialog.setTitle("提示");
// 设置ProgressDialog 提示信息
m_pDialog.setMessage("这是一个圆形进度条对话框");
// 设置ProgressDialog 标题图标
// 设置ProgressDialog 的进度条是否不明确
m_pDialog.setIndeterminate(false);
// 设置ProgressDialog 是否可以按退回按键取消
m_pDialog.setCancelable(true);
m_pDialog.show();
4
完成,单击按钮 就可以弹出对话框,(包含进度条~~)
E. android 怎么自定义绘制如下图中这种进度条
下面是安卓学习手册中实现各种进度条的截图:
要想看各种进度条的实现代码和文档,直接去360手机助手中下载安卓学习手册,例子文档随便看。
1、说明
在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度。一个进度条也可不确定其进度。在不确定模式下,进度条显示循环动画。这种模式常用于应用程序使用任务的长度是未知的。
2、XML重要属性
android:progressBarStyle:默认进度条样式
android:progressBarStyleHorizontal:水平样式
3 重要方法
getMax():返回这个进度条的范围的上限
getProgress():返回进度
getSecondaryProgress():返回次要进度
incrementProgressBy(int diff):指定增加的进度
isIndeterminate():指示进度条是否在不确定模式下
setIndeterminate(boolean indeterminate):设置不确定模式下
setVisibility(int v):设置该进度条是否可视
4 重要事件
onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件
5进度条的样式
Widget.ProgressBar.Horizontal长形进度
Androidxml 布局:
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal "
/>
源码:
private ProgressBar mProgress;
private int mProgressStatus=0;
private Handler mHandler=newHandler();
@Override
protected void onCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgress=(ProgressBar)findViewById(R.id.progress_bar);
new Thread(new Runnable(){
@Override
public void run(){
while(mProgressStatus<100){
mProgressStatus=doWork();
mHandler.post(new Runnable(){
@Override
public void run(){
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
效果图:
带第二进度的进度条
xml配置如下:
<ProgressBar
android:id="@+id/progress_bar_with_second"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="40"
android:secondaryProgress="70"
android:paddingTop="20dp"
android:paddingBottom="20dp"/>
这里我们设置了初始的进度为40,android:progress的值在mini和max之间即mini<=progressvalue<=max
设置了第二进度条的进度值为70,该值也在mini和max之间。
效果如下:
不确定模式进度条
xml配置文件:
<ProgressBar
android:id="@+id/progress_bar_indeterminate"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateBehavior="cycle"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:progress="40" />
这里通过android:indeterminate="true"设置了当前为无模式进度条
效果如图:
普通圆形进度:Widget.ProgressBar.Inverse
<ProgressBar
android:id="@+id/progress_bar1"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="50"
android:background="#ff00ff"
android:paddingTop="4dp" />
通过android:backgroup设置了背景色
F. android网络加载进度条怎么使用
由于Android的界面更新只能通过自己的UI线程进行操作,所以我们需要用到Handler在进行更新界面的操作。
1、声明变量
private Handler handler = new Handler();
private ProgressDialog progressDialog = null;
2、在开始进行网络连接时显示进度条对话框
progressDialog = ProgressDialog.show(MyActivity.this, "请稍等...", "获取数据中...", true);
3、在handler.post中进行界面更新
public void setListAdapter(){
handler.post(new Runnable() {
public void run() {
//将获取到的数据更新到列表中
MyListView.setAdapter(saImageItems);
}
}
});
4、开个新的线程进行网络连接获取数据
new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
//向服务器请求数据
mapList=MyAPI.getAllDatas();
setListAdapter(mapList);
//更新完列表数据,则关闭对话框
progressDialog.dismiss();
}}).start();
整个过程就这样完成了,下面是效果图:
G. android 进度条样式 怎么改
Android系统提供了两大类进度条样式,长形进度条(progressBarStyleHorizontal) 和圆形进度条(progressBarStyleLarge)。
android 进度条样式更改:
第一种
(默认样式(中等圆形))
进度条用处很多,比如,应用程序装载资源和网络连接时,可以提示用户稍等,这一类进度条只是代表应用程序中某一部分的执行情况,而整个应用程序执行情况呢,则可以通过应用程序标题栏来显示一个进度条,这就需要先对窗口的显示风格进行设置"requestWindowFeature(Window.FEATURE_PROGRESS)"。
H. android 绘制进度条
看起来代码挺长,其实都是在获取自定义属性,没什么技术含量。
宽度不变,所以的自定义属性不涉及宽度,高度呢,只考虑不是EXACTLY的情况(用户明确指定了,就不管了),根据padding和进度条宽度算出自己想要的,如果非EXACTLY下,进行exceptHeight封装,传入给控件进行测量高度。
横向的滚动条绘制肯定需要一些属性,比如已/未到达进度的颜色、宽度,文本的颜色、大小等。
本来呢,我是想通过系统ProgressBar的progressDrawable,从里面提取一些属性完成绘制需要的参数的。但是,最终呢,反而让代码变得复杂。所以最终还是改用自定义属性。 说道自定义属性,大家应该已经不陌生了。
1、
1、自定义属性
values/attr_progress_bar.xml:
[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="">
<attr name="progress_unreached_color" format="color" />
<attr name="progress_reached_color" format="color" />
<attr name="progress_reached_bar_height" format="dimension" />
<attr name="progress_unreached_bar_height" format="dimension" />
<attr name="progress_text_size" format="dimension" />
<attr name="progress_text_color" format="color" />
<attr name="progress_text_offset" format="dimension" />
<attr name="progress_text_visibility" format="enum">
<enum name="visible" value="0" />
<enum name="invisible" value="1" />
</attr>
</declare-styleable>
<declare-styleable name="RoundProgressBarWidthNumber">
<attr name="radius" format="dimension" />
</declare-styleable>
</resources>
2、构造中获取
[java] view plain
public class extends ProgressBar
{
private static final int DEFAULT_TEXT_SIZE = 10;
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
/**
* painter of all drawing things
*/
protected Paint mPaint = new Paint();
/**
* color of progress number
*/
protected int mTextColor = DEFAULT_TEXT_COLOR;
/**
* size of text (sp)
*/
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
/**
* offset of draw progress
*/
protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET);
/**
* height of reached progress bar
*/
protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
/**
* color of reached bar
*/
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
/**
* color of unreached bar
*/
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
/**
* height of unreached progress bar
*/
protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
/**
* view width except padding
*/
protected int mRealWidth;
protected boolean mIfDrawText = true;
protected static final int VISIBLE = 0;
public (Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public (Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);
setHorizontalScrollBarEnabled(true);
obtainStyledAttributes(attrs);
mPaint.setTextSize(mTextSize);
mPaint.setColor(mTextColor);
}
/**
* get the styled attributes
*
* @param attrs
*/
private void obtainStyledAttributes(AttributeSet attrs)
{
// init values from custom attributes
final TypedArray attributes = getContext().obtainStyledAttributes(
attrs, R.styleable.);
mTextColor = attributes
.getColor(
R.styleable._progress_text_color,
DEFAULT_TEXT_COLOR);
mTextSize = (int) attributes.getDimension(
R.styleable._progress_text_size,
mTextSize);
mReachedBarColor = attributes
.getColor(
R.styleable._progress_reached_color,
mTextColor);
mUnReachedBarColor = attributes
.getColor(
R.styleable._progress_unreached_color,
DEFAULT_COLOR_UNREACHED_COLOR);
mReachedProgressBarHeight = (int) attributes
.getDimension(
R.styleable._progress_reached_bar_height,
mReachedProgressBarHeight);
mUnReachedProgressBarHeight = (int) attributes
.getDimension(
R.styleable._progress_unreached_bar_height,
mUnReachedProgressBarHeight);
mTextOffset = (int) attributes
.getDimension(
R.styleable._progress_text_offset,
mTextOffset);
int textVisible = attributes
.getInt(R.styleable._progress_text_visibility,
VISIBLE);
if (textVisible != VISIBLE)
{
mIfDrawText = false;
}
attributes.recycle();
}
3、onMeasure
刚才不是出onDraw里面写写就行了么,为什么要改onMeasure呢,主要是因为我们所有的属性比如进度条宽度让用户自定义了,所以我们的测量也得稍微变下。
[java] view plain
@Override
protected synchronized void onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
{
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (heightMode != MeasureSpec.EXACTLY)
{
float textHeight = (mPaint.descent() + mPaint.ascent());
int exceptHeight = (int) (getPaddingTop() + getPaddingBottom() + Math
.max(Math.max(mReachedProgressBarHeight,
mUnReachedProgressBarHeight), Math.abs(textHeight)));
heightMeasureSpec = MeasureSpec.makeMeasureSpec(exceptHeight,
MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
测量完,就到我们的onDraw了~~~
I. android 怎么使水平进度条动起来 最好有个例子 我是新手
进度条的操作你应该会的吧。
例子网上其实有很多,我大致说一下。
首先你要写一个线程,然后循环i从1开始,i++,一直到100
然后去修改你主线程的进度条
这样你的进度条就动起来了!当到100的时候,传一个intent 跳转activity
J. android 进度条
顶部放一个ProgressBar或者ImageView,进入的时候开始转圈,转完了就隐藏起来,view.setVisibility(View.INVISIBLE);再把其他界面显示出来就好了,view.setVisibility(View.VISIBLE);