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进度条的特效源码,这个源码是在源码天堂那个网站上转载过来的,我已经修改一部分了,感觉很实用的,大家可以学习一下吧,我就不上传源码了,大家可以直接到那个网站上下载吧. 源码天堂下载地 ...
- Android 进度条改变图片透明度
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Android 进度条
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Android—进度条
layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- Android——进度条ProgressBar
1.activity_progressbar.xml <?xml version="1.0" encoding="utf-8"?><Linea ...
- android进度条的使用
// 导入按钮事件 btnsearch.setOnClickListener(new View.OnClickListener() { @Override public void on ...
- Android 进度条按钮实现(ProgressButton)
有些App在点击下载按钮的时候,可以在按钮上显示进度,我们可以通过继承原生Button,重写onDraw来实现带进度条的按钮. Github:https://github.com/imcloudflo ...
- Android 进度条对话框ProgressDialog
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Android进度条控件ProgressBar使用
ProgressBar有四种样式,圆形的(大,中,小)和直条形的(水平) 对应的style为 <LinearLayout xmlns:android="http://schemas.a ...
随机推荐
- hdu1711 Number Sequence
Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...
- 认识Backbone (五)
Backbone.Router(路由)/ Backbone.history(历史) Backbone.Router 为客户端路由提供了许多方法,并能连接到指定的动作(actions)和事件(even ...
- 制作service服务,shell脚本小例子(来自网络)
事先准备工作:源码安装apache .安装目录为/usr/local/httpd 任务需求:1.可通过 service httpd start|stop|status|restart 命令对服务进行控 ...
- 座IO理解力
一般堵塞IO服务器通信,通常有一个单独的Acceptor线程负责监控client联系,它接收client对于每个请求连接后client分配用于处理一个新的线程,处理后.返回应答给client.线程才销 ...
- 取缔Chrome装载电脑管家的广告过滤脚本代码
今天Chrome调试脚本.加载在下面的脚本中找到的内容: /* 电脑管家chrome 广告过滤 */ var GJAD_CS = { elemhideElt : null, setElemhideCS ...
- A*算法进入
作者文章链接:http://www.policyalmanac.org/games/aStarTutorial.htm 启示式搜索:启示式搜索就是在状态空间中的搜索对每个搜索的位置进行评估,得到最好的 ...
- configure.ac:20: error: Autoconf version 2.65 or higher is required
安装thrift例如,下面的问题出现: configure.ac:20: error: Autoconf version 2.65 or higher is required wget http:// ...
- STL之容器适配器queue的实现框架
说明:本文仅供学习交流,转载请标明出处,欢迎转载! 上篇文章STL之容器适配器stack的实现框架已经介绍了STL是怎样借助基础容器实现一种经常使用的数据结构stack (栈),本文介绍下第二种STL ...
- Bulk Insert具体订单
Bulk Insert具体订单 BULK INSERT与用户指定的格式的数据文件复制到数据库表或视图. 语法: BULK INSERT [ [ 'database_name'.][ 'owner' ] ...
- [原创].NET 业务框架开发实战之六 DAL的重构
原文:[原创].NET 业务框架开发实战之六 DAL的重构 .NET 业务框架开发实战之六 DAL的重构 前言:其实这个系列还是之前的".NET 分布式架构开发实战 ",之所以改了 ...