简体   繁体   English

加载Webview时如何在Android上使用Shimmer?

[英]How to use Shimmer for Android while a webview is loading?

This is the library I would like to use: https://github.com/RomainPiel/Shimmer-android 这是我想使用的库: https : //github.com/RomainPiel/Shimmer-android

It's basically a textview that shimmers but I would like to display this while my webview is loading. 它基本上是一个闪烁的文本视图,但是我想在加载Web视图时显示它。 However, as a textview, the shimmer requires a layout. 但是,作为文本视图,微光需要布局。 Should I create a new activity that shows the shimmer textview and display that while the web view is loading or what? 我应该创建一个新的活动来显示微光的textview并在加载Web视图时显示该活动还是什么?

Here's where I'm trying to implement this code: 这是我尝试实现此代码的地方:

webView.setWebViewClient(new WebViewClient(){
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon)
    {
        // TODO show you progress image
        super.onPageStarted(view, url, favicon);
        Log.i("WEBVIEW", "Loading");
    }

    @Override
    public void onPageFinished(WebView view, String url)
    {
        // TODO hide your progress image
        super.onPageFinished(view, url);
        Log.i("WEBVIEW", "Loading Done");
    }
});

I'd never used the WebView , but your idea looks good. 我从未使用过WebView ,但是您的想法看起来不错。

Just use FrameLayout , to use the advantage of Z ordering (In FrameLayout the views are ordered by depth). 只需使用FrameLayout ,即可利用Z排序的优势(在FrameLayout ,视图按深度排序)。 Like this: 像这样:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android">

    <WebView
        ...Properties
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout
        ...Properties
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.romainpiel.shimmer.ShimmerTextView
            android:id="@+id/shimmer_tv"
            android:text="@string/shimmer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#444"
            android:textSize="50sp"/>
    </LinearLayout>
</FrameLayout>

So the LinearLayout will be on the top of WebView, and use bringToFront() on WebView and hide the LinearLayout to show the WebView when page finish loading. 因此, LinearLayout将位于WebView的顶部,并在WebView上使用bringToFront()并隐藏LinearLayout以在页面加载完成时显示WebView

Take a look at this page explaning this behavior. 看一下此行为说明页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM