【问题标题】:Android: Help animating views?Android:帮助动画视图?
【发布时间】:2015-08-05 11:36:47
【问题描述】:

我的布局由一个 EditText 和一个 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>

当用户向下滚动 WebView 时,我希望 EditText 向上移动并消失,所以我重写了 WebView 中的 onScrollChanged 方法:

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);
    }

}

但是实现的效果是EditText移动到顶部但又立即回到原来的位置。你怎么看?

【问题讨论】:

    标签: android webview translate-animation


    【解决方案1】:

    你必须打电话:

    translateAnimation.setFillEnabled(true); 
    

    之前

    translateAnimation.setFillAfter(true);  
    

    而且它有效。

    【讨论】:

      【解决方案2】:

      尝试添加translateAnimation.setFillAfter(true)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-27
        • 1970-01-01
        • 2011-03-14
        • 2011-08-28
        相关资源
        最近更新 更多