I made a dialog with both Enter and Exit slow animations. But the dialog contains a webview myMsg
(that loads a local file, so no delay) and messes up the animation.
With the code below (no webview), the dialog works perfectly, animating both at Enter and at Exit. However, if I uncomment the
line //builder.setView(myMsg)
, the Exit animation still works perfectly, but the Enter animation is not performed (or performed too fast). Funny thing, if I minimize the app and maximize it again, the Enter dialog animation is performed fine.
It's like the webview load messes the Enter animation. I tried to show the dialog after the webview is loaded, with the same results.
Isn't that crazy?? Any clue of what is happening, and how to solve it? Any help would be appreciated.
Here's the relevant part of the code:
WebView myMsg = new WebView(context);
myMsg.loadUrl("file:///android_asset/page.html");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(R.drawable.ic_launcher);
//builder.setView(myMsg);
builder.setTitle("Some Title");
final AlertDialog dialog = builder.create();
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.windowAnimations = R.style.AnimateDialog;
dialog.show();
dialog.getWindow().setAttributes(lp);
and in styles,
<style name="AnimateDialog">
<item name="android:windowEnterAnimation">@anim/in_left</item>
<item name="android:windowExitAnimation">@anim/out_left</item>
</style>
EDIT
I tried with a setWebViewClient
, but without luck (without the line dialog.getWindow().setLayout...
the Enter animation simply does not work):
WebView myMsg = new WebView(context);
myMsg.getSettings().setJavaScriptEnabled(true);
myMsg.loadUrl("file:///android_asset/" + page);
myMsg.setBackgroundColor(0);
myMsg.setSoundEffectsEnabled(true);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("SomeTitle");
builder.setView(myMsg);
final AlertDialog dialog = builder.create();
myMsg.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
dialog.show();
dialog.getWindow().setWindowAnimations(R.style.AnimateDialog);
dialog.getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);
}
}
EDIT2
I also tried with Dialog instead of AlertDialog, with an xml layout, getting identical problems (tried also WebView.loadData
instead of WebView.loadUrl
, same problems):
final Dialog d = new Dialog(context);
d.setContentView(R.layout.viewhtml);
d.setTitle("SomeTitle");
// Without this, Enter animation does not work
d.getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT);
WebView wv = (WebView) d.findViewById(R.id.webview);
wv.loadUrl("file:///android_asset/" + page);
wv.setBackgroundColor(0);
d.getWindow().setWindowAnimations(R.style.AnimateDialog);
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
d.show();
}
});
and this is Dialog xml layout file:
<?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
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:soundEffectsEnabled="true" >
</WebView>
</LinearLayout>
EDIT3
I just realized that the same problem happens when using a TextView
with TextView.setText(Html.fromHTML...)
instead of a WebView
. Moreover, if I add dialog.getWindow().setLayout(600,800)
after dialog.show()
, the animation is performed as expected. So it seems that the problem is that the animation is not performed without knowing beforehand the dialog size?