Reputation: 3209
I want to move button to the center, show it , then move to the corner.
But it won't move, it immediately appears in the corner. Why?
upd 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);
Upvotes: 4
Views: 3581
Reputation: 3209
Well, I've found a solution. Works, but strangely enough, this nowhere mentioned. Just need to make a pause, even 10ms. The rest the same.
....
//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);
Upvotes: 7