Note that there are some explanatory texts on larger screens.

plurals
  1. POCan an Android WebView do a translationX animation with hardware acceleration?
    primarykey
    data
    text
    <p>I had read somewhere that hardware acceleration should work for all built in Android views; however, when I try to do a slide animation with a WebView the entire Web Content goes blank for the duration of the animation.</p> <p>I'll write a little app so if you would like to see it for yourselves, you can try. The app will do a slide animation every time a page loads in the WebView. We'll slide between an ImageView and a WebView. The ImageView will just contain a screenshot of the WebView itself. Stick the following code in onCreate for your activity:</p> <pre><code>final WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("http://www.google.com"); final ImageView myImageView = (ImageView) findViewById(R.id.imageView); myWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { myWebView.setDrawingCacheEnabled(true); myWebView.buildDrawingCache(); myImageView.setImageBitmap(Bitmap.createBitmap(myWebView.getDrawingCache())); myWebView.setDrawingCacheEnabled(false); myImageView.setVisibility(View.VISIBLE); myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); ObjectAnimator webViewAnimator = ObjectAnimator.ofFloat(myWebView, "translationX", myWebView.getWidth(), 0); webViewAnimator.setDuration(SLIDE_DURATION); ObjectAnimator imageViewAnimator = ObjectAnimator.ofFloat(myImageView, "translationX", 0, -myWebView.getWidth()); imageViewAnimator.setDuration(SLIDE_DURATION); AnimatorSet set = new AnimatorSet(); set.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { myWebView.setLayerType(View.LAYER_TYPE_NONE, null); myImageView.setVisibility(View.GONE); } }); set.playTogether(webViewAnimator, imageViewAnimator); set.start(); } } </code></pre> <p>Ensure you have android:hardwareAccelerated="true" in your Manifest.xml</p> <p>Also, in your main_layout.xml:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;ImageView android:id="@+id/imageView" android:contentDescription="@string/image_view_description" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Now every time you load a page, there will be a slide transition between an ImageView (containing a screenshot of the WebView), and the WebView itself. </p> <p><strong>The bug is not reproducable in the JellyBean simulator, however it does happen on all ICS/JellyBean devices tested so far...</strong></p> <p>Any insight into this issue would be greatly appreciated. Note that although I can simply disable Hardware Acceleration on the WebView by setting it's Layer Type to LAYER_TYPE_SOFTWARE and this will fix the "blanking out" issue, I would like to keep Hardware Acceleration enabled because of the rendering benefits.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload