Android:帮助动画视图?

发布于 2024-10-16 20:52:30 字数 2083 浏览 2 评论 0原文

我的布局由 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 移动到顶部,但立即返回到原来的位置。你怎么认为?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼窥荷 2024-10-23 20:52:31

你必须调用:

translateAnimation.setFillEnabled(true); 

Before

translateAnimation.setFillAfter(true);  

并且它有效。

You have to call:

translateAnimation.setFillEnabled(true); 

Before

translateAnimation.setFillAfter(true);  

And it works.

辞慾 2024-10-23 20:52:31

尝试添加 translateAnimation.setFillAfter(true)

Try adding translateAnimation.setFillAfter(true).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文