android的进度条使用
android的进度条
1、实现的效果


2、布局代码
先写一个my_browser.xml文件 存放WebView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
进度条布局
然后写一个broser.xml存放进度条的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/tvtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:textSize="20sp" android:layout_centerVertical="true"/>
<ProgressBar
android:id="@+id/pb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="gone"
android:layout_alignParentBottom="true" >
</ProgressBar> </RelativeLayout>
WebChromeClient
重写onProgressChanged和onReceivedTitle事件(进度条载入完毕后使用动画渐退)
/**
* MyWebChromeClient.java
* 版权全部(C) 2012
* 创建:cuiran 2012-10-16 下午3:05:34
*/
package com.cayden.citygirl.activity; import android.app.Activity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.TextView; /**
* TODO
* @author cuiran
* @version TODO
*/
public class MyWebChromeClient extends WebChromeClient { private Activity activity; private ProgressBar pb; private Animation animation; private TextView tvtitle; public MyWebChromeClient(Activity activity) { this.activity = activity; } @Override
public void onProgressChanged(WebView view, int newProgress) {
pb=(ProgressBar)activity.findViewById(R.id.pb);
pb.setMax(100);
if(newProgress<100){
if(pb.getVisibility()==View.GONE) pb.setVisibility(View.VISIBLE);
pb.setProgress(newProgress);
}else{
pb.setProgress(100);
animation=AnimationUtils.loadAnimation(activity, R.anim.animation);
// 执行动画
pb.startAnimation(animation);
// 将 spinner 的可见性设置为不可见状态
pb.setVisibility(View.INVISIBLE);
}
super.onProgressChanged(view, newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) { tvtitle=(TextView)activity.findViewById(R.id.tvtitle); tvtitle.setText(title);
super.onReceivedTitle(view, title); } }
进度条的动画样式 res/anim/animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="700"/>
</set>
5、程序启动类
/**
* ProgressActivity.java
* 版权全部(C) 2012
* 创建:cuiran 2012-10-16 下午3:13:49
*/
package com.cayden.citygirl.activity; import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebView; /**
* TODO
* @author cuiran
* @version TODO
*/
public class ProgressActivity extends Activity { private WebView browser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.my_browser); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.broser); browser = (WebView) findViewById(R.id.webView); // currentWebView=browser; browser.setWebChromeClient(new MyWebChromeClient(ProgressActivity.this)); browser.loadUrl("http://shop.paipai.com/731681975/"); } }
android的进度条使用的更多相关文章
- Android 设置进度条背景
Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...
- android 自定义进度条颜色
android 自定义进度条颜色 先看图 基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程! 这个没法了只能看源码了,还好下载了源码, sources\b ...
- Android之进度条2
我之前有写过一篇“Android之进度条1”,那个是条形的进度条(显示数字进度),这次实现圆形进度条. 点击查看Android之进度条1:http://www.cnblogs.com/caidupin ...
- android多线程进度条
多线程实现更新android进度条. 实例教程,详细信息我已经注释 android多线程进度条 01package com.shougao.hello; 02 03import android ...
- 最简单的android自定义进度条样式
一.自定义圆形进度条样式 1.在安卓项目drawable目录下新建一个xml文件如下:<?xml version="1.0" encoding="utf-8&quo ...
- Android多种进度条使用详解
在这里,总结一下loading进度条的使用简单总结一下. 一.说起进度条,必须说说条形进度条,经常都会使用到嘛,特别是下载文件进度等等,还有像腾讯QQ安装进度条一样,有个进度总给人良好的用户体验. 先 ...
- android ProgressBar 进度条的进度两端是圆角的方法
转自 http://www.jianshu.com/p/6e7ea842d5ce 另外工作原理可以参考http://blog.csdn.net/lan603168/article/details/44 ...
- Android -- ProgressBar(进度条的使用)
我们在开发程序是经常会需要软件全屏显示.自定义标题(使用按钮等控件)和其他的需求,今天这一讲就是如何控制Android应用程序的窗体显示. requestWindowFeature可以设置的值有:(具 ...
- android之进度条组件ProgressBar
首先是main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android& ...
随机推荐
- 十大流行Linux发行版
[2013年5月13日 51CTO外电头条]Linux是功能强大的常用操作系统之一,目前它在计算机操作系统领域的发展速度越来越快.它提供了出色的性能和速度.Linux用起来非常稳定而可靠.它还提供了几 ...
- 【转】【iOS】导航栏那些事儿
原文网址:http://www.jianshu.com/p/f797793d683f 参考文章 navigationItem UINavigationItem UINavigationBar UIBa ...
- 【转】Android异步消息处理机制完全解析,带你从源码的角度彻底理解
原文网址:http://blog.csdn.net/guolin_blog/article/details/9991569 转载请注明出处:http://blog.csdn.net/guolin_bl ...
- Erlang之IO编程
Erlang用于操纵文件I/O的模块有:file模块:打开.读.写.关闭文件已经操作目录的方法基本都在这里 filename模块:提供平台独立方式用于操纵文件名 filelib模块:file模块的扩展 ...
- 自杀程序&递归删除目录
自杀程序,删掉自身,包括执行程序所在的文件夹. 仅在windows下进行了测试,使用语言C# string fileName = Path.GetTempPath() + "killmyse ...
- CF GYM 100703M It's complicate
题意:龙要做茶,需要n种原料,给出他有的原料个数,和每份茶需要的原料个数,和每种原料的价格,要求做整数份茶,把他之前有的原料用完最少要花多少钱. 解法:水题. 代码: #include<stdi ...
- win7安装gevent时报错 whl is not a supported wheel on this platform.
1.首先强烈推荐一个站点 在使用pip安装python协程包gevent时,需要很多依赖,很多需要编译的底层支持等等,不能拿来就用.总之很多麻烦的事儿. 这个强烈推荐一个站点,里面都是一些编译好的py ...
- NOIP2009 最优贸易
3. 最优贸易 (trade.pas/c/cpp) [问题描述] C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个城市之间 多只有一条道路直接相连.这 m 条道 ...
- Python几个算法实现
1.平衡点问题: 比如int[] numbers = {1,3,5,7,8,25,4,20}; 25前面的总和为24,25后面的总和也是24,25这个点就是平衡点:假如一个数组中的元素,其前面的部分等 ...
- 【Hadoop学习】Apache Hadoop项目简介
正在撰写,稍后来访……