我想将按钮移动到中心,显示它,然后移动到角落。
但它不会移动,它会立刻出现在角落里。为什么呢?
更新 Android 5.1,API 22。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// remember true position/size
final RelativeLayout.LayoutParams layoutParams_= (RelativeLayout.LayoutParams) mapFollowButton.getLayoutParams();
// create temp position/size from which will move
final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams((int) (150*density), (int) (150*density));
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mapFollowButton.setLayoutParams(layoutParams);
mapFollowButton.setVisibility(View.INVISIBLE);
mapFollowButton.invalidate();
final ChangeBounds transition= new ChangeBounds();
transition.setDuration(1000L);
TransitionManager.beginDelayedTransition((ViewGroup) findViewById(R.id.mainRL),transition);
//here expected to move to true position from center
mapFollowButton.setLayoutParams(layoutParams_);
mapFollowButton.setVisibility(View.VISIBLE);
} else
mapFollowButton.setVisibility(View.VISIBLE);
答案 0 :(得分:4)
好吧,我找到了解决方案。工作,但奇怪的是,这没有提到。只需要暂停,甚至10ms。其余的一样。
....
//mapFollowButton.invalidate();
mapFollowButton.postDelayed(new Runnable() {
@Override
public void run() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
final ChangeBounds transition= new ChangeBounds();
transition.setDuration(1000L);
TransitionManager.beginDelayedTransition((ViewGroup) findViewById(R.id.mainRL),transition);
}
mapFollowButton.setLayoutParams(layoutParams_);
mapFollowButton.setVisibility(View.VISIBLE);
}
},10);