Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:扩展动画不工作_Android_Animation - Fatal编程技术网

Android:扩展动画不工作

Android:扩展动画不工作,android,animation,Android,Animation,我正在使用以下代码设置可展开布局的动画: class ExpandAnimation extends Animation { private View _view; private int _startHeight; private int _finishHeight; public ExpandAnimation( View view, int startHeight, int finishHeight ) { _view = view;

我正在使用以下代码设置可展开布局的动画:

class ExpandAnimation extends Animation {
    private View _view;
    private int _startHeight;
    private int _finishHeight;

    public ExpandAnimation( View view, int startHeight, int finishHeight ) {
        _view = view;
        _startHeight = startHeight;
        _finishHeight = finishHeight;
        setDuration(500);
        System.out.println(_startHeight);
        System.out.println(_finishHeight);
    }

    @Override
    protected void applyTransformation( float interpolatedTime, Transformation t ) {
        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;
    }
};
每次单击按钮时都会创建此动画。它被正确调用(选中System.out.println并打印正确的值),但是在emulator中,动画只运行15次中的一次。确切地说,隐藏它工作得很好,但扩展只工作几次(在模拟器上,无法在手机上工作)

有什么问题吗

谢谢转发

编辑:我尝试设置动画的布局是FrameLayout。它将TextView作为子级,finishHeight由TextView测量高度来测量。这些值是正确的。我还尝试在将转换应用于重画布局时调用textView.requestLayout(),但它不起作用。它仍然只是偶尔膨胀。如果您需要更多代码,请随时询问。

呼叫

((View) toExpand.getParent()).invalidate();

就在StartImation解决了我的问题之后。必须在其他设备上检查它,但我认为它会起作用。

我将可点击区域放大了很多,在手机上效果更好,但仍然不是100%。有时,我的手机会识别出我点击了两个项目,并将它们同时展开。但我认为它们现在已经足够大了(比如1,2厘米)。。。我真的不知道如何使这项工作做得更好