The Android progress bar uses

Source: Internet
Author: User

Android progress bar 1, the effect of the implementation

2. Layout code

First write a my_browser.xml file to store 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:o rientation= "vertical" >        <webview        android:id= "@+id/webview"        android:layout_width= "Fill_parent"        android:layout_height= "Fill_parent"/></linearlayout>

Progress bar Layout

And write a broser.xml that stores the progress bar.

<?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

overriding Onprogresschanged and Onreceivedtitle events (using animation fade after the progress bar is loaded)

/** * Mywebchromeclient.java * All rights reserved (C) 
 * Created: Cuiran 2012-10-16 pm 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 Webchromeclie NT {private activity activity; private ProgressBar PB; private Animation Animation; private TextView tvtitle; public MyWeb Chromeclient (activity activity) {this.activity = activity;} @Override public void onprogresschanged (WebView view, int ne wprogress) {pb= (ProgressBar) Activity.findviewbyid (R.ID.PB), Pb.setmax (+), if (newprogress<100) {if ( Pb.getvisibility () ==view.gone) pb.setvisibility (view.visible); Pb.setprogress (newprogress);  }else{pb.setprogress (+); Animation=animationutils.loadanimation (activity, r.anim.animation);//Performing animations Pb.startanimation (animation); Sets the visibility of the spinner to an invisible state 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);} }


The animation style of the progress bar 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= "" "/> </set>

5. Program Startup class
/** * Progressactivity.java * copyright All (C)  * Created: Cuiran 2012-10-16 pm 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/"); }}


The Android progress bar uses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.