beginDelayedTransition用法

要改变某个控件的位置,可以用修改布局参数后setLayoutParams,如果想给这个过程加上动画效果,则可以在父节点上调用TransitionManager.beginDelayedTransition


private void changePosition() {
    TransitionManager.beginDelayedTransition(viewRoot);

    LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) square.getLayoutParams();
    if (positionChanged) {
        lp.gravity = Gravity.CENTER;
    } else {
        lp.gravity = Gravity.LEFT;
    }
    positionChanged = !positionChanged;
    square.setLayoutParams(lp);
}

你可能感兴趣的:(Android)