Can anyone point to solution how to make expand animation of Description TextView in Android Market animation? There are TextView wrapped into FrameLayout which expands after clicking on 'More' label.
TextView expand animation like in Android Market
Solution:
private static int measureViewHeight( View view2Expand, View view2Measure ) {
try {
Method m = view2Measure.getClass().getDeclaredMethod("onMeasure", int.class, int.class);
m.setAccessible(true);
m.invoke(view2Measure,
MeasureSpec.makeMeasureSpec(view2Expand.getWidth(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
} catch (Exception e) {
return -1;
}
int measuredHeight = view2Measure.getMeasuredHeight();
return measuredHeight;
}
static public void expandOrCollapse( View view2Expand, View view2Measure,
int collapsedHeight ) {
if (view2Expand.getHeight() < collapsedHeight)
return;
int measuredHeight = measureViewHeight(view2Expand, view2Measure);
if (measuredHeight < collapsedHeight)
measuredHeight = collapsedHeight;
final int startHeight = view2Expand.getHeight();
final int finishHeight = startHeight <= collapsedHeight ?
measuredHeight : collapsedHeight;
view2Expand.startAnimation(new ExpandAnimation(view2Expand, startHeight, finishHeight));
}
class ExpandAnimation extends Animation {
private final View _view;
private final int _startHeight;
private final int _finishHeight;
public ExpandAnimation( View view, int startHeight, int finishHeight ) {
_view = view;
_startHeight = startHeight;
_finishHeight = finishHeight;
setDuration(220);
}
@Override
protected void applyTransformation( float interpolatedTime, Transformation t ) {
final int newHeight = (int)((_finishHeight - _startHeight) * interpolatedTime + _startHeight);
_view.getLayoutParams().height = newHeight;
_view.requestLayout();
}
@Override
public void initialize( int width, int height, int parentWidth, int parentHeight ) {
super.initialize(width, height, parentWidth, parentHeight);
}
@Override
public boolean willChangeBounds( ) {
return true;
}
};
can you give more detail,how to callback measureViewHeight()?what is View view2Expand, View view2Measure ? –
Zilpah
Of course. In my case, view2Measure - is TextView. view2Expand - FrameLayout which contains TextView. We measure full height of text view and apply it to FrameLayout. FrameLayout is presented for fade effect when text is collapsed (see https://mcmap.net/q/282273/-force-fading-edge-on-textview) –
Unscrupulous
@Unscrupulous Can you post more how you go about achieving all this I dint get how you did it –
Gambrel
first you create a method with two parameters private static int measureViewHeight( View view2Expand, View view2Measure ) and then you call the same method by passing three parameters....measureViewHeight(view2Expand, view2Measure, context); can you explain why you have done that?????????? –
Kurtz
@Kurtz its a typo. There are no need to pass Context into measureViewHeight –
Unscrupulous
anyway......the code shows anomalous behaviour......it only collapse but it does not expand on the click of the view......can you provide detail expalanation or some samples that you have already done ..... –
Kurtz
@Kurtz Sorry, I do not have enough time at the moment for full example, you may provide your sources and I'll try to find mistake. –
Unscrupulous
© 2022 - 2024 — McMap. All rights reserved.