TextView在Android市场上扩展动画

TextView在Android市场上扩展动画,android,animation,textview,expand,Android,Animation,Textview,Expand,有人能指出如何在Android Market动画中制作Description TextView的扩展动画的解决方案吗?文本视图包装到FrameLayout中,单击“更多”标签后展开。解决方案: private static int measureViewHeight( View view2Expand, View view2Measure ) { try { Method m = view2Measure.getClass().getDeclaredMethod("onM

有人能指出如何在Android Market动画中制作Description TextView的扩展动画的解决方案吗?文本视图包装到FrameLayout中,单击“更多”标签后展开。

解决方案:

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;
    }
};
private static int measureViewHeight(查看视图2扩展,查看视图2测量){
试一试{
方法m=view2Measure.getClass().getDeclaredMethod(“onMeasure”,int.class,int.class);
m、 setAccessible(true);
m、 调用(view2Measure,
MeasureSpec.makeMeasureSpec(view2Expand.getWidth(),MeasureSpec.AT_最多),
MeasureSpec.makeMeasureSpec(0,MeasureSpec.unspect));
}捕获(例外e){
返回-1;
}
int measuredhight=view2Measure.getmeasuredhight();
返回测量高度;
}
静态公共空隙扩展器或塌陷(视图2扩展,视图2测量,
int折叠高度){
if(view2Expand.getHeight()final int finishHeight=starthelight您能否提供更多详细信息,如何回调measureViewHeight()?什么是View view2Expand,View view2Measure?当然。在我的例子中,view2Measure-是TextView。view2Expand-包含TextView的FrameLayout。我们测量文本视图的完整高度并将其应用于FrameLayout。FrameLayout在文本折叠时显示淡入效果(请参阅)@HighFlyer你能发布更多关于如何实现这一切的信息吗?我想知道你是如何做到的首先你创建了一个带有两个参数的方法私有静态int MeasureView(查看view2Expand,查看view2Measure),然后你通过传递三个参数调用同一个方法…MeasureView(查看2Expand,查看2Measure,上下文)你能解释一下你为什么这么做吗?Prativa这是一个打字错误。没有必要将上下文传递到MeasureView中