TranslateAnimation绑定到onClickListener但使用ontouchListener启动[android]

时间:2015-07-22 04:57:49

标签: android onclick swipe ontouchlistener ontouch

我有3个图像视图按钮从外部滑动并在点击时进入屏幕(使用翻译动画)

我还有ontouch监听器的隐形imageview,可以改变屏幕中央的图片:

dddd

问题是当我点击垂直矩形时不会出现3个按钮! 但是logcat确实显示方法已被触发,但是当我使用滑动手势在中心旋转图像时 - 按钮确实出现(滑入/滑出屏幕)

public class Page7 extends Activity{
public void onCreate(){
//..... some findViewbyId stuff here

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (launch_animation_counter == 0) {
                    Log.d("x", " show buttons");//this appears in logcat
                        launch_animation_counter = 1;
                        play.startAnimation(play_move_right);//this line does not always launch animation!
                        content.startAnimation(content_move_right);
                        record.startAnimation(record_move_right);
                    } else if (launch_animation_counter == 1) {
                    Log.d("x", " hide buttons");
                        launch_animation_counter = 0;
                        play.startAnimation(play_move_left);
                        content.startAnimation(content_move_left);
                        record.startAnimation(record_move_left);
                    }
            }
        });
swipe_area.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
//                Log.d("x", "swipe touched....");
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        x1 = event.getRawX();
                        break ;
                    case MotionEvent.ACTION_UP:
                        x2 = event.getRawX();
                        if(x1 < x2){
                            Log.d("x", "слева направо");
                            switch (pencil_counter){
                                case 1:
                                    Log.d("x", " case 1");
                                    image.setBackgroundResource(R.drawable.page7_pencils7);
                                    pencil_counter = 7 ;
                                    break ;
                                case 2:
                                    Log.d("x", " case 2");
                                    image.setBackgroundResource(R.drawable.page7_pencils1);
                                    pencil_counter = 1 ;
                                    break ;

}

这些是动画代码:

play_move_right = new TranslateAnimation(
            Animation.ABSOLUTE, 0,
            Animation.ABSOLUTE, -240,
            Animation.ABSOLUTE, 0,
            Animation.ABSOLUTE, 0
    );
    play_move_right.setFillEnabled(true);
    play_move_right.setDuration(500);

    play_move_left = new TranslateAnimation(
            Animation.ABSOLUTE, 0,
            Animation.ABSOLUTE, 240,
            Animation.ABSOLUTE, 0,
            Animation.ABSOLUTE, 0
    );
    play_move_left.setFillEnabled(true);
    play_move_left.setDuration(500);

0 个答案:

没有答案