Android 在幻灯片上显示视图

Android 在幻灯片上显示视图,android,drag,motionevent,Android,Drag,Motionevent,我是android开发的新手。我想知道,当用户向上滑动时,我如何才能显示视图。 看我的布局。! 现在,当用户向上滑动蓝色视图时,我希望显示一个视图,并且当用户向下滑动时,视图应该消失。 正如我所知,并试图在谷歌上找到我没有得到任何成功,所以请帮助我 我试着这么做,但什么也没发生 public class MainActivity extends ActionBarActivity { private LinearLayout slideUp; @Override p

我是android开发的新手。我想知道,当用户向上滑动时,我如何才能显示视图。 看我的布局。!

现在,当用户向上滑动蓝色视图时,我希望显示一个视图,并且当用户向下滑动时,视图应该消失。 正如我所知,并试图在谷歌上找到我没有得到任何成功,所以请帮助我

我试着这么做,但什么也没发生

public class MainActivity extends ActionBarActivity {

    private LinearLayout slideUp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        slideUp = (LinearLayout) findViewById(R.id.ll_slideUp);

        slideUp.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent touchevent) {
                float x1 = 0, y1 = 0, x2, y2;
                switch (touchevent.getAction()) {
                    // when user first touches the screen we get x and y coordinate

                    case MotionEvent.ACTION_DOWN: {
                        x1 = touchevent.getX();
                        y1 = touchevent.getY();
                        break;
                    }
                    case MotionEvent.ACTION_UP: {
                        x2 = touchevent.getX();
                        y2 = touchevent.getY();

                        //if left to right sweep event on screen
                        if (x1 < x2) {
                            Toast.makeText(MainActivity.this, "Left to Right Swap Performed", Toast.LENGTH_LONG).show();
                        }

                        // if right to left sweep event on screen
                        if (x1 > x2) {
                            Toast.makeText(MainActivity.this, "Right to Left Swap Performed", Toast.LENGTH_LONG).show();
                        }

                        // if UP to Down sweep event on screen
                        if (y1 < y2) {
                            Toast.makeText(MainActivity.this, "UP to Down Swap Performed", Toast.LENGTH_LONG).show();
                        }

                        //if Down to UP sweep event on screen
                        if (y1 > y2) {
                            Toast.makeText(MainActivity.this, "Down to UP Swap Performed", Toast.LENGTH_LONG).show();  // Show your view here when use slides up
                        }
                        break;
                    }
                }
                return false;
            }

        });
    }


}

那么,如何显示带有按钮和少量文本视图的线性布局??
float x1,y1,x2,y2;
 view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent touchevent) {
             switch (touchevent.getAction())
             {
                    // when user first touches the screen we get x and y coordinate
                     case MotionEvent.ACTION_DOWN: 
                     {
                         x1 = touchevent.getX();
                         y1 = touchevent.getY();
                         break;
                    }
                     case MotionEvent.ACTION_UP: 
                     {
                         x2 = touchevent.getX();
                         y2 = touchevent.getY(); 

                         //if left to right sweep event on screen
                         if (x1 < x2) 
                         {
                             Toast.makeText(this, "Left to Right Swap Performed", Toast.LENGTH_LONG).show();
                          }

                         // if right to left sweep event on screen
                         if (x1 > x2)
                         {
                             Toast.makeText(this, "Right to Left Swap Performed", Toast.LENGTH_LONG).show();
                         }

                         // if UP to Down sweep event on screen
                         if (y1 < y2) 
                         {
                             Toast.makeText(this, "UP to Down Swap Performed", Toast.LENGTH_LONG).show();
                         }

                         //if Down to UP sweep event on screen
                         if (y1 > y2)
                         {
                             Toast.makeText(this, "Down to UP Swap Performed", Toast.LENGTH_LONG).show();  // Show your view here when use slides up
                          }
                         break;
                     }
             }
             return false;
        }

    });