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

时间:2013-01-31 00:28:27

标签: android animation android-side-navigation

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

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

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

如果您想查看整个图片,请参阅我的其他帖子: 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();
                    }
                });

1 个答案:

答案 0 :(得分:0)

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

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

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