I\'m trying to create a Master/Detail transaction in a single fragment. I thought of using LinearLayout as the container of my edittext for my header. Then a RecyclerView fo
Improved my answer using David's comment.
I would animate "topMargin" of your header:
LinearLayout _headerLayout; // expected to be set in "onCreateView"
int _headerHeight; // expected to be set in "onCreateView" as _headerHeight = getHeaderHeight();
Animation _hideAnimation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) _headerLayout.getLayoutParams();
params.topMargin = -(int) (_headerHeight * interpolatedTime);
_headerLayout.setLayoutParams(params);
}
};
Animation _showAnimation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) _headerLayout.getLayoutParams();
params.topMargin = (int) (_headerHeight * (interpolatedTime - 1));
_headerLayout.setLayoutParams(params);
}
};
private int getHeaderHeight()
{
_headerLayout.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
return _headerLayout.getMeasuredHeight();
}
Hiding header:
_headerLayout.clearAnimation();
_headerLayout.startAnimation(_hideAnimation);
Showing header:
_headerLayout.clearAnimation();
_headerLayout.startAnimation(_showAnimation);
You can also easily set duration for your animations:
_hideAnimation.setDuration(2000) // will hide in 2 seconds
_showAnimation.setDuration(2000) // will show in 2 seconds