开发者

Android: Help animating views?

My layout consists of an EditText and a subclass of WebView:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<EditText android:id="@+id/addressbar" 
              android:layout_width="fill_parent" 
              android:layout_height="wrap_content" 
              android:background="@android:drawable/editbox_background"
               />

 <com.android.ibrowser.myWebView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/browser"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

/>

</LinearLayout>

When the user scrolls down the WebView I would like the EditText to move up and disappear, So I override the onScrollChanged method in WebView:

protected void onScrollChanged (int l, int t, int oldl, int oldt){

    super.onScrollChanged(l, t, oldl, oldt);


    if (addressBar.getBottom() > 0){

        AnimationSet animation = new AnimationSet(true);
        TranslateAnimation translateAnimation = new TranslateAnimation(0, 0
                , -t + oldt, -t + oldt);
        translateAnimation.setDuration(100);
        animation.addAnimation(translateAnimation);
        animation.setFillAfter(true);

        animation.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationEnd(Animation arg0) {
                addressBar.clearAnimation();
                // Change view to state B by modifying its layout params and scroll
            }



            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }
        });
        addressBar.startAnimation(animation);
开发者_如何学编程    }

}

But the effect achieved is that the EditText moves to the top but immediately goes back to its original position. What do you think?


You have to call:

translateAnimation.setFillEnabled(true); 

Before

translateAnimation.setFillAfter(true);  

And it works.


Try adding translateAnimation.setFillAfter(true).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜