导航:首页 > 操作系统 > android进度条demo

android进度条demo

发布时间:2023-03-29 15:37:56

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();

整个过程就这样完成了,下面是效果图:

② Android自定义View实现可拖拽的进度条

在onSizeChanged方法中进行计算,这时可以得到一条与控件宽度相同的直线,并把路径设置给PathMeasure

使用PathMeasure得出当前进度的路径并进行绘制,这里我将上一步的绘制放在了一起

这个矩形的宽度需要我们用绘制最长的文字来确定其宽高

另外矩形的显示位置也是以当前进度所在的点为中心点

文字显示的位置计算起来就比较简单了,直接用上一步算出的矩形的中心点即可,不过这里需要调整文字绘制的垂直的偏移,这样才能实现文字垂直居中

实现拖拽需要对onTouchEvent方法进行处理,也就是当手指触摸矩形区域的时候,根据手指横向滑动的偏移来设置当前的进度,具体如下

为了适配高度的wrap_content属性,我们需要计算出控件最小需要显示的高度

这里我们是用显示进度的矩形的高度作为控件最小的高度的,因为矩形的高度是所有图形最高的一个

https://gitee.com/itfitness/seek-progress-bar

③ 怎样实现在android实现带进度条的上传效果

实现在android实现带进度条的上传效果效果如图:


用到以下两个类就可实现带进度条的文件上传:


1、CustomMultiPartEntity extends MultipartEntity,


2、HttpMultipartPost extends AsyncTask


代码如下:


import java.io.FilterOutputStream;


import java.io.IOException;


import java.io.OutputStream;


import java.nio.charset.Charset;


import org.apache.http.entity.mime.HttpMultipartMode;


import org.apache.http.entity.mime.MultipartEntity;



public class CustomMultipartEntity extends MultipartEntity {


private final ProgressListener listener;


public CustomMultipartEntity(final ProgressListener listener) {


super();


this.listener = listener;


}


public CustomMultipartEntity(final HttpMultipartMode mode, final ProgressListener listener) {


super(mode);


this.listener = listener;


}


public CustomMultipartEntity(HttpMultipartMode mode, final String boundary,


final Charset charset, final ProgressListener listener) {


super(mode, boundary, charset);


this.listener = listener;


}


@Override


public void writeTo(final OutputStream outstream) throws IOException {


super.writeTo(new CountingOutputStream(outstream, this.listener));


}


public static interface ProgressListener {


void transferred(long num);


}



public static class CountingOutputStream extends FilterOutputStream {


private final ProgressListener listener;


private long transferred;


public CountingOutputStream(final OutputStream out, final ProgressListener listener) {


super(out);


this.listener = listener;


this.transferred = 0;


}


public void write(byte[] b, int off, int len) throws IOException {


out.write(b, off, len);


this.transferred += len;


this.listener.transferred(this.transferred);


}


public void write(int b) throws IOException {


out.write(b);


this.transferred++;


this.listener.transferred(this.transferred);


}


}


}


该类计算写入的字节数,我们需要在实现ProgressListener中的trasnfered()方法,更行进度条



public class HttpMultipartPost extends AsyncTask<HttpResponse, Integer, TypeUploadImage> {



ProgressDialogpd;



longtotalSize;



@Override


protectedvoidonPreExecute(){


pd= newProgressDialog(this);


pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);


pd.setMessage("Uploading Picture...");


pd.setCancelable(false);


pd.show();


}



@Override


(HttpResponse... arg0) {


HttpClienthttpClient = newDefaultHttpClient();


HttpContexthttpContext = newBasicHttpContext();


HttpPosthttpPost = newHttpPost("http://herpderp.com/UploadImage.php");



try{


= newCustomMultipartEntity(


newProgressListener() {



@Override


public void transferred(longnum){


publishProgress((int) ((num / (float) totalSize) * 100));


}


});



// We use FileBody to transfer an image


multipartContent.addPart("uploaded_file", newFileBody(


newFile(m_userSelectedImagePath)));


totalSize= multipartContent.getContentLength();



// Send it


httpPost.setEntity(multipartContent);


HttpResponseresponse = httpClient.execute(httpPost, httpContext);


String serverResponse = EntityUtils.toString(response.getEntity());



ResponseFactoryrp = newResponseFactory(serverResponse);


return(TypeImage) rp.getData();


}



catch(Exception e) {


System.out.println(e);


}


returnnull;


}



@Override


protectedvoidonProgressUpdate(Integer... progress){


pd.setProgress((int) (progress[0]));


}



@Override


protectedvoidonPostExecute(TypeUploadImageui) {


pd.dismiss();


}


}

在 transferred()函数中调用publishProgress((int) ((num / (float) totalSize) * 100));


在onProgressUpdate()实现上传进度的更新操作

④ android 圆形进度条 中间怎么写 demo

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@android:id/background">
<shape>
<corners android:radius="20dp" />

<gradient
android:angle="0"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:startColor="#ff9d9e9d" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="20dp" />

<gradient
android:angle="0"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:startColor="#80ffd300" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="20dp" />

<gradient
android:angle="0"
android:endColor="#8000ff00"
android:startColor="#80ff0000" />
</shape>
</clip>
</item>
<!--
下面是标准的绿色进度条
<item
android:id="@android:id/background"
android:drawable="@drawable/security_progress_bg">
</item>
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/security_progress">
</item>
<item
android:id="@android:id/progress"
android:drawable="@drawable/security_progress">
</item>
-->

</layer-list>

⑤ Android开发怎么自定义绘制如下图中这种进度条急需!在线等!

一)变换前背景

先来看看progressbar的属性:
1. <ProgressBar
2. android:id="@+id/progressBar"
3. style="?android:attr/progressBarStyleHorizontal"
4. android:layout_width="match_parent"
5. android:layout_height="wrap_content"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:indeterminate="false"
9. android:padding="2dip"
10. android:progress="50" />
根据style="?android:attr/progressBarStyleHorizontal",我们找到源码中的style.xml
1. <style name="Widget.ProgressBar.Horizontal">
2. <item name="android:indeterminateOnly">false</item>
3. <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
4. <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
5. <item name="android:minHeight">20dip</item>
6. <item name="android:maxHeight">20dip</item>
7. </style>
看到
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
木有,继续发掘源码,找到drawable下面的progress_horizontal.xml,这就是我们今天的主角了:
1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
2.
3. <item android:id="@android:id/background">
4. <shape>
5. <corners android:radius="5dip" />
6. <gradient
7. android:startColor="#ff9d9e9d"
8. android:centerColor="#ff5a5d5a"
9. android:centerY="0.75"
10. android:endColor="#ff747674"
11. android:angle="270"
12. />
13. </shape>
14. </item>
15.
16. <item android:id="@android:id/secondaryProgress">
17. <clip>
18. <shape>
19. <corners android:radius="5dip" />
20. <gradient
21. android:startColor="#80ffd300"
22. android:centerColor="#80ffb600"
23. android:centerY="0.75"
24. android:endColor="#a0ffcb00"
25. android:angle="270"
26. />
27. </shape>
28. </clip>
29. </item>
30.
31. <item android:id="@android:id/progress">
32. <clip>
33. <shape>
34. <corners android:radius="5dip" />
35. <gradient
36. android:startColor="#ffffd300"
37. android:centerColor="#ffffb600"
38. android:centerY="0.75"
39. android:endColor="#ffffcb00"
40. android:angle="270"
41. />
42. </shape>
43. </clip>
44. </item>
45.
46. </layer-list>
看到android:id="@android:id/progress"木有,看到android:id="@android:id/secondaryProgress"木有
把这个文件复制到自己工程下的drawable,就可以随心所欲的修改shape的属性,渐变,圆角等等
那么怎么放一个图片进去呢,ok,新建progress_horizontal1.xml:
1. <?xml version="1.0" encoding="utf-8"?>
2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3.
4. <item android:id="@android:id/progress" android:drawable="@drawable/progressbar" />
5.
6. </layer-list>
在android:drawable中指定你处理好的图片
然后回到布局中
1. <ProgressBar
2. android:id="@+id/progressBar1"
3. android:layout_width="match_parent"
4. android:layout_height="wrap_content"
5. android:layout_below="@+id/progressBar"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:background="@drawable/progress_bg"
9. android:indeterminate="false"
10. android:indeterminateOnly="false"
11. android:maxHeight="20dip"
12. android:minHeight="20dip"
13. android:padding="2dip"
14. android:progress="50"
15. android:progressDrawable="@drawable/progress_horizontal1" />
android:background="@drawable/progress_bg"指定背景
android:progressDrawable="@drawable/progress_horizontal1"前景使用上面的progress_horizontal1

要是还不行

你来我们群里说吧

这里是开发者互相学习交流的 有大神

让他们给你解释你的疑问 号 码look at my n a m e.....

⑥ 跪求一个 android 视频缓存完整demo(带进度条)

在做手机开发时,经常碰到一些比较耗时的操作,这个时候进度条就开始派上用场了。 这个demo展示了ProgressBar进度条和ProgressDialog进度框。 一、ProgressDialog进度框,效果如图所示: 代码如下: 复制代码 代码如下: //进度对话框按钮监听 class ProssButtonListener implements OnClickListener { @Override public void onClick(View v) { myDialog = ProgressDialog.show(ProgressbarDemo.this, "进度条标题", "进度条内容", true); new Thread() { public void run() { try { /* 在这里写上要背景运行的程序片段 */ /* 为了明显看见效果,以暂停3秒作为示范 */ sleep(3000); } catch (Exception e) { e.printStackTrace(); } finally { // 卸载所创建的myDialog对象。 myDialog.dismiss(); } } }.start(); /* 开始运行运行线程 */ } } 二、进度条对话框,这里用两种情况来动态显示进度条刻度 1、handle方法 效果图如下: 代码如下: 复制代码 代码如下: //进度条handle按钮监听 class ProssBarHandleButtonListener implements OnClickListener { @Override public void onClick(View v) { progressBarHandle.setVisibility(View.VISIBLE); myProssBarhandleText.setVisibility(View.VISIBLE); progressBarHandle.setMax(1000); new Thread() { public void run() { for(int i=0;i<=1000;){ try { /* 在这里写上运行的进度条 */ Message msg = new Message(); msg.what = 1; msg.getData().putInt("size", i); handler.sendMessage(msg);//handle发送消息 /* 为了明显看见效果,以暂停1秒作为示范 */ sleep(100); i+=10; } catch (Exception e) { handler.obtainMessage(-1).sendToTarget(); e.printStackTrace(); } } } }.start(); /* 开始运行运行线程 */ } } //handle接收消息 private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { switch (msg.what) { case 1: progressBarHandle.setProgress(msg.getData().getInt("size")); float num = (float)progressBarHandle.getProgress()/(float)progressBarHandle.getMax(); int result = (int)(num*100); System.out.println("progressBarHandle.getProgress()======="+progressBarHandle.getProgress()); myProssBarhandleText.setText(result+ "%"); if(progressBarHandle.getProgress()==progressBarHandle.getMax()){ Toast.makeText(ProgressbarDemo.this, "下载成功", 1).show(); progressBarHandle.setVisibility(View.GONE); myProssBarhandleText.setVisibility(View.GONE); } break; case -1: Toast.makeText(ProgressbarDemo.this,"下载失败", 1).show(); break; } } }; 2、使用AsyncTask方法,效果图与handle效果一样 具体代码如下: 复制代码 代码如下: //进度条synctask按钮监听 class ProssBarSyncButtonListener implements OnClickListener { @Override public void onClick(View v) { new AsyncLoader().execute((Void)null); } } //AsyncTask 任务执行 class AsyncLoader extends AsyncTask<Void, Integer, Integer> { @Override // 在doInBackground方法执行前执行 protected void onPreExecute(){ progressBarHandle.setVisibility(View.VISIBLE); myProssBarhandleText.setVisibility(View.VISIBLE); progressBarHandle.setMax(100000); } // 做具体的耗时操作 protected Integer doInBackground(Void... params) { //这里以1万的进度条刻度来显示 int totalSize = 100000; for (int i = 0; i < 100000; ) { publishProgress(i); //通过推送消息传递数据给onProgressUpdate方法执行 i+=10; } return totalSize; } // 在doInBackground方法执行过程中执行 protected void onProgressUpdate(Integer... progress) { progressBarHandle.setProgress(progress[0]); float num = (float)progressBarHandle.getProgress()/(float)progressBarHandle.getMax(); int result = (int)(num*100); myProssBarhandleText.setText(result+ "%"); } // 在doInBackground方法结束后执行 protected void onPostExecute(Integer result) { Toast.makeText(ProgressbarDemo.this, "下载成功,下载了"+result, 1).show(); myProssBarhandleText.setVisibility(View.GONE); progressBarHandle.setVisibility(View.GONE); } } 点击下载DEMO示例

⑦ android中如何获取listview中其中一个Item中的进度条对象来更新下载进度

public class MainActivity extends Activity
{
private ListView listView;
private DownloadAdapter adapter;
private List<String>行纯 lists = new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

for (int i = 0; i < 10; i++)
{
lists.add("察仔button" + i);
}
listView = (ListView) findViewById(R.id.listView1);
adapter = new DownloadAdapter(this, lists);
listView.setAdapter(adapter);

}

}

public class DownloadAdapter extends BaseAdapter
{
private Context context;
private List<String> list;
private LayoutInflater inflater;

public DownloadAdapter(Context context, List<String> list)
{
this.context = context;
this.list = list;
inflater = LayoutInflater.from(context);
}

@Override
public int getCount()
{
// TODO Auto-generated method stub
return list.size();
}

@Override
public Object getItem(int position)
{
// TODO Auto-generated method stub
return list.get(position);
}

@Override
public long getItemId(int position)
{
//败带汪 TODO Auto-generated method stub
return list.get(position).hashCode();
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
MyHolder myHolder = null;
if (convertView == null)
{
convertView = inflater.inflate(R.layout.item, null);
myHolder = new MyHolder();
myHolder.bar = (ProgressBar) convertView
.findViewById(R.id.progressBar1);
myHolder.button = (Button) convertView.findViewById(R.id.button1);
convertView.setTag(myHolder);
}
else
{
myHolder = (MyHolder) convertView.getTag();
}

myHolder.button.setText(list.get(position));
MyDownLoadThread down = new MyDownLoadThread(myHolder.bar,
myHolder.button);

myHolder.button.setOnClickListener(down);
return convertView;
}

class MyHolder
{
private ProgressBar bar;
private Button button;
}

public class MyDownLoadThread extends Thread implements OnClickListener
{

private ProgressBar pBar;
private Button btn;
private int index = 0;
private boolean isStart = false;

private Handler handler = new Handler()
{

@Override
public void handleMessage(Message msg)
{
pBar.setProgress(index);
}

};

public MyDownLoadThread(ProgressBar pBar, Button btn)
{
this.pBar = pBar;
this.btn = btn;
}

@Override
public void onClick(View v)
{
if (!isStart)
{
isStart = true;
btn.setText("开始下载");
pBar.setMax(100);
this.start();
}

}

@Override
public void run()
{
while (index <= 100)
{
index++;
handler.sendEmptyMessage(0);
try
{
sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if (index > 100)
{
btn.setText("下载完成");
break;
}

}

}
}

}

简单的demo 仅供参考,希望对你有用

⑧ 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了~~~

⑨ android 的ExpandableListView下面怎么样放置进度条

1. 先弄一个TextView作为指示器放在ListView的上面,跟列表上缘平齐。
2. 处理列表的上下滚动回调:
Java代码 if(第一行是group){ if(第二行也是group) 隐藏指示器; </SPAN></li> else if(第二行是第启高一行展开的第一个child) 显示指示器; </SPAN></li>} else { </SPAN></li> if(第二行是group 且第一行显示不完整时) 隐藏指示器; </SPAN></li>} if(第一行是group){ if(第二行也是group) 隐藏指示器; else if(第二行是第一行展开的第一个child) 显示指示器; } else { if(第二行是group 且第一行显示不完整时) 隐藏指示器; } 就这样了,是吧?Java代码 public class GroupHeaderIndicator extends TextView implements OnScrollListener { </SPAN></li> @Override </SPAN></li> public void onScroll(AbsListView view, int firstVisibleItem, </SPAN></li> int visibleItemCount, int totalItemCount) { </SPAN></li> // TODO Auto-generated method stub </SPAN></li> ExpandableListView listView = (ExpandableListView)view; //当前第一行归属的组ID </SPAN></li> int gid = ExpandableListView.getPackedPositionGroup(listView.getExpandableListPosition(firstVisibleItem)); </SPAN></li> //当前第一行的子ID </SPAN></li> int cid = ExpandableListView.getPackedPositionChild(listView.getExpandableListPosition(firstVisibleItem)); </SPAN></li> //当前第二行的子ID </SPAN></li> int nid = ExpandableListView.getPackedPositionChild(listView.getExpandableListPosition(firstVisibleItem+1)); </SPAN></li> BuddiesListAdapter adapter=(BuddiesListAdapter)listView.getExpandableListAdapter(); String gtitle=(gid>-1)?adapter.getGroup(gid).toString():""; </SPAN></li> //如果第一行和第迹渗二行都是组header,不需要显示 </SPAN></li> if(cid==-1 && nid==-1){ </SPAN></li> this.setVisibility(View.GONE); </SPAN></li> } else { </SPAN></li> //当前真的是一个child,而且下一行是group </SPAN></li> if(nid==-1 && cid>=0){ </SPAN></li>悄州尺 this.setVisibility(View.GONE); </SPAN></li> return; </SPAN></li> } this.setVisibility(View.VISIBLE); </SPAN></li> this.setText(gtitle); </SPAN></li> this.postInvalidate(); </SPAN></li> } } } public class GroupHeaderIndicator extends TextView implements OnScrollListener { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // TODO Auto-generated method stub ExpandableListView listView = (ExpandableListView)view; //当前第一行归属的组ID int gid = ExpandableListView.getPackedPositionGroup(listView.getExpandableListPosition(firstVisibleItem)); //当前第一行的子ID int cid = ExpandableListView.getPackedPositionChild(listView.getExpandableListPosition(firstVisibleItem)); //当前第二行的子ID int nid = ExpandableListView.getPackedPositionChild(listView.getExpandableListPosition(firstVisibleItem+1)); BuddiesListAdapter adapter=(BuddiesListAdapter)listView.getExpandableListAdapter(); String gtitle=(gid>-1)?adapter.getGroup(gid).toString():""; //如果第一行和第二行都是组header,不需要显示 if(cid==-1 && nid==-1){ this.setVisibility(View.GONE); } else { //当前真的是一个child,而且下一行是group if(nid==-1 && cid>=0){ this.setVisibility(View.GONE); return; } this.setVisibility(View.VISIBLE); this.setText(gtitle); this.postInvalidate(); } } } 一切就这么简单,然后看看它放的位置是:Xhtml代码 <FrameLayout xmlns:android=" http://schemas.android.com/apk/res/android"</SPAN></li> android:layout_width="fill_parent" </SPAN></li> android:layout_height="fill_parent" </SPAN></li> android:padding="8.0dip" </SPAN></li> android:layout_weight="1.0"> </SPAN></li> <ExpandableListView </SPAN></li> android:id="@id/buddies_list" </SPAN></li> android:scrollbars="vertical" </SPAN></li> android:layout_width="fill_parent" </SPAN></li> android:layout_height="fill_parent" </SPAN></li> android:layout_marginLeft="0.0dip" </SPAN></li> android:drawSelectorOnTop="false" </SPAN></li> android:scrollingCache="true" </SPAN></li> android:layout_weight="1.0" </SPAN></li> android:fastScrollEnabled="false" </SPAN></li> android:footerDividersEnabled="true" </SPAN></li> android:cacheColorHint="#00000000" </SPAN></li> android:groupIndicator="@drawable/expander_group" </SPAN></li> style="@style/Widget.ListViewGreen" mce_style="@style/Widget.ListViewGreen" </SPAN></li> /> </SPAN></li> <cn.sharetop.demo.ui.GroupHeaderIndicator </SPAN></li> android:id="@id/buddies_group_indicator" </SPAN></li> android:textColor="#333333" </SPAN></li> android:gravity="left|center" </SPAN></li> android:paddingLeft="32.0dip" </SPAN></li> android:layout_width="fill_parent" </SPAN></li> android:layout_height="44.0dip" </SPAN></li> android:background="@drawable/expand_group_bar" </SPAN></li> /> </SPAN></li> </FrameLayout> </SPAN></li><FrameLayout xmlns:android=" http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="8.0dip" android:layout_weight="1.0"> <ExpandableListView android:id="@id/buddies_list" android:scrollbars="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="0.0dip" android:drawSelectorOnTop="false" android:scrollingCache="true" android:layout_weight="1.0" android:fastScrollEnabled="false" android:footerDividersEnabled="true" android:cacheColorHint="#00000000" android:groupIndicator="@drawable/expander_group" style="@style/Widget.ListViewGreen" mce_style="@style/Widget.ListViewGreen" /> <cn.sharetop.demo.ui.GroupHeaderIndicator android:id="@id/buddies_group_indicator" android:textColor="#333333" android:gravity="left|center" android:paddingLeft="32.0dip" android:layout_width="fill_parent" android:layout_height="44.0dip" android:background="@drawable/expand_group_bar" /> </FrameLayout>我为了省事,直接从TextView中派生出这个指示器,其实你可以更复杂点,从一个ViewGroup之类的东西来做出更多的效果。细心的朋友可以发现了,在QQ中,当上移列表时,有一个效果是下一个group header将指示器给推出屏幕的,图省事,我没这样做,留给兄弟你去扩展了。此外,反编译QQ的代码可知,其实它的实现是自己做了一个叫 IphoneTreeView的类,继承了ExpandableListView,这样做更灵活也更好,同样,如果要实现更完美的效果,还有很多事情要做的。

⑩ 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设置了背景色

阅读全文

与android进度条demo相关的资料

热点内容
dbug命令 浏览:349
开逛app如何加好友 浏览:958
ftpdos命令下载文件 浏览:73
华为如何打开语音服务器 浏览:242
python中的idle 浏览:1000
五轴联动数控编程 浏览:965
换一台电脑如何远程云服务器 浏览:132
阿里云怎么买云服务器 浏览:664
java提取文字 浏览:97
阿里云服务器同人账号问题 浏览:418
5分钟解压轴题 浏览:341
安卓桌面二级文件夹 浏览:188
eps文档加密 浏览:261
手机怎么做pdf 浏览:162
ug曲面pdf 浏览:279
液化气还是压缩气 浏览:950
阿里云公共ntp服务器地址 浏览:991
金字塔学习机编程 浏览:684
多边形扫描线算法Python 浏览:718
快手app快手粉条在哪里 浏览:256