如何使LinearLayout中的X轴下我的手指动了?我的、动了、手指、LinearLayout

由网友(爾西裝℡男人摸洋風華絕代)分享简介:我需要知道我能做些什么,使一个的LinearLayout 用我的手指一起移动,但我想只移动X轴,而不是在Y I need to know what i can do to make a LinearLayout move together with my finger but i want to move only...

我需要知道我能做些什么,使一个的LinearLayout 用我的手指一起移动,但我想只移动X轴,而不是在Y

I need to know what i can do to make a LinearLayout move together with my finger but i want to move only the X axis and not the Y.

和动完之后,当你手指的的LinearLayout 返回到原来的X位置。

And after finished moving, when you "finger up" the LinearLayout back to original X position.

我怎么能做到这一点?

推荐答案

假设LL是你的线性布局的名称:

assume ll is the name of your linear layout:

    ll.setOnTouchListener(new OnTouchListener() {

        float lastX;

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            View item = v;

            switch(event.getAction())
            {
            case MotionEvent.ACTION_DOWN:
                lastX = event.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                item.scrollBy((int) (event.getX()-lastX), 0);
                lastX = event.getX();
                break;
            case MotionEvent.ACTION_UP:
                item.scrollTo(0, 0);

            }
            return false;
        }
    });
阅读全文

相关推荐

最新文章