Reputation: 1407
My app has a small web view that I want to animate into place once the page has finished loading. My code looks like this:
view.setVisibility(View.VISIBLE);
TranslateAnimation anim=new TranslateAnimation(0.0f, 0.0f,
view.getLayoutParams().height, 0.0f);
anim.setDuration(5);
anim.setInterpolator(new LinearInterpolator());
view.startAnimation(anim);
It animates all right, but I can't seem to control the speed. I've set the value for setDuration() to 5, 500, 5000, 5000000 - all to no discernible effect.
Is there something else I need to do to control animation duration?
BTW my base SDK is 1.6.
Upvotes: 1
Views: 11760
Reputation: 1407
Here's what I've found in my testing.
Again, YMMV and this may only apply to WebViews.
Upvotes: 0
Reputation: 26525
I use XML approach for setting animation for a layout.
translate.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:fromYDelta="-100%"
android:toYDelta="0"
android:duration="500" />"
/>
</set>
To control the animation duration, you could try changing android:duration ="500"
to values you require.
layout_anim_controller.xml
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animationOrder="reverse"
android:animation="@anim/translate" />
Setting the Animation for the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layoutAnimation="@anim/layout_anim_controller"
/>
</LinearLayout>
Maybe this helps a little bit in the right direction.
Upvotes: 1