I have a RelativeLayout within which is a ScrollView and an EditText, and if a user shifts focus to the EditText I want the ScrollView to hide itself until they finish. That part was easy, but I also would like the RelativeLayout to shrink/expand gradually to present a nice transition, rather than snapping open/close.
Here is the code which hides the ScrollView when the EditText gains focus:
private class myCostBoxFocusListener implements View.OnFocusChangeListener {
public void onFocusChange(View v, boolean hasFocus) {
ScrollView sView = (ScrollView) ((RelativeLayout)v.getParent().getParent()).getChildAt(1);
//A bit hacky, I know, but it works.
if (hasFocus) {
sView.setVisibility(View.GONE);
}
else if(!hasFocus) {
sView.setVisibility(View.VISIBLE);
}
}
}
and this works just fine. However, the code I strung together for trying to animate the open/close isn't working. It's currently causing the ScrollView items to fade in/out over 2 seconds, while the RelativeLayout is still snapping open/closed immediately.
LayoutTransition transition = new LayoutTransition();
ObjectAnimator a1 = ObjectAnimator.ofFloat(null, View.SCALE_Y, 0, 1);
AnimatorSet animator = new AnimatorSet();
animator.setStartDelay(0);
animator.play(a1);
transition.setAnimator(LayoutTransition.CHANGE_APPEARING, animator);
transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, animator);
transition.setDuration(2000);
RelativeLayout rView = (RelativeLayout) dialogNew.findViewById(R.id.ocrmain_group_select_parent);
rView.setLayoutTransition(transition);
I've tried using LayoutTransition_APPEARING/DISAPPEARING instead of CHANGE_, but that doesn't animate what I want. I'm clearly missing the concept here, and would greatly appreciate some pointers on how I'm conceptualizing this incorrectly.