Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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
TextView fling动画Android_Android_Textview - Fatal编程技术网

TextView fling动画Android

TextView fling动画Android,android,textview,Android,Textview,现在,我可以删除文本视图扔没有任何动画。您将如何在flings上设置文本视图动画以显示此动作 textView.setOnTouchListener(new OnSwipeTouchListener(this) { public void onSwipeRight() { layout.removeView(textView) } public void onSwipeLeft() { layout.removeView(textView

现在,我可以删除文本视图扔没有任何动画。您将如何在flings上设置文本视图动画以显示此动作

textView.setOnTouchListener(new OnSwipeTouchListener(this) {
    public void onSwipeRight() {
        layout.removeView(textView)
    } 
    public void onSwipeLeft() {
        layout.removeView(textView);
    }
});
每个蓝色矩形框都是文本视图


Android视图有ViewPropertyAnimator类,如果您想要一些简单的动画,它将为您解决这个问题。 在您的例子中,最简单的方法是在onFling方法中调用TextView的animate

虽然,这种动画会在用户的触摸释放时触发,所以这可能不是他期望看到的确切行为。
在这种情况下,您可能希望将动画逻辑与onScroll方法相结合

您是否可以添加一些代码,以便我们可以查看您现在拥有的内容。布局也不错。
boolean isHidden;    
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    // ... fling check
    float velocity = Math.abs(velocityX / 8000f);
    long duration = (long) (100 / velocity); // calculate duration based on velocity
    textView.animate().translationX(isHidden ? 0 : 500).alpha(isHidden ? 1 : 0).setDuration(duration).start();
    isHidden != isHidden;
}