Android:更新 v.layout 参数后调用 requestLayout() 导致布局恢复到原来的位置



我有框架布局,其中包含两个相对布局,一个在另一个之上。当用户单击按钮时,顶部的按钮会将屏幕向右移动 80%。然后底部的一个变得可点击。这就是它的样子。

                                 FrameLayout
          RelativeLayout (bottom)              RelativeLayout (top)
            FilterWidgets                   Open/close button, ListView

使用新的动画 api 在 3.0+ 上实现它真的很容易实现,该 API 是基于属性的动画。对于 3.0 之前的版本,因为动画是基于视图的。所以我最终手动修改了 onAnimationEnd 上的布局属性。调用请求布局使其永久化,但只是为了发现布局恢复到原始位置。有人知道如何永久移动布局吗?

如果你想看到整个画面,请参阅我的另一篇文章:https://stackoverflow.com/questions/14541265/changecursor-cause-layout-container-of-the-listview-to-reposition

theTranslationX.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator nullPointer) {
                        v.clearAnimation();
                        int theL = isMenuOn() ? 0 : v.getLeft() + getFilterWidth();
                        int theR = isMenuOn() ? v.getWidth() : v.getLeft() + getFilterWidth() + v.getWidth();
                        int theHeight = v.getHeight();
                        int theT = 0;
                        v.layout(theL, theT, theR, theHeight);
                        v.requestLayout();
                    }
                });

这已经晚了 9 个月,但请尝试使用:

yourView.layout(left,top,right,bottom); //all parameters are type int

但是我不认为这是永久性的,当您调用requestLayout()时,视图的位置仍然会被重置,但请尝试一下。

最新更新