点击界面控件留白部分,退出该界面

来源:互联网 发布:新加坡旅游消费知乎 编辑:程序博客网 时间:2024/06/06 04:49

点击评论界面的留白部分,退出评论界面并实现退出动画,实现的代码如下:

//点击留白部分,进行退出动画
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction()==MotionEvent.ACTION_DOWN) {
PointF pointF = new PointF(event.getX(),event.getY());
if(!isInView(pointF))
{
Animation animation = AnimationUtils.loadAnimation(act,R.anim.ta_pulldown);
animation.setAnimationListener(listener);
pinglun_rl.setAnimation(animation);
}
return true;
}


return super.onTouchEvent(event);
}
private boolean isInView(PointF pf)
{
boolean bo = false;
int left = pinglun_rl.getLeft();
int right = pinglun_rl.getRight();
int top = pinglun_rl.getTop();
int bottom = pinglun_rl.getBottom();
if(pf.x>left&&pf.x<right&&pf.y>top&&pf.y<bottom)
{
bo = true;
}
return bo;
}
private Animation.AnimationListener listener = new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
act.finish();
}
};

0 0
原创粉丝点击