Scroll between activities like Snapchat?

I am developing an application that has several actions, and I want to implement swipe (left, right, up, down). Transition between actions (not fragments) such as snapchat. I did some research, but I could not find the right approach. Can anyone suggest how I can approach the situation above? Thank.

+4
source share
2 answers

I do not believe that you can get the same smooth napkins using actions. (Someone can fix me). You can perform a manual capture and download the next action. You will not see the “Preview”, and it will be very similar to just clicking a button.

The smoothness that a presentation pager provides is due to fragments. Again (if I'm not mistaken), only one action can be provided to the user. Therefore, you cannot show a preview of the next action. Fragments go around because you can have multiple fragments.

I'm not sure if you have a good reason not to use fragments. They are fairly straightforward, and you can more or less use actions. You will have a snippet for activity.

, , , , , . , .

http://developer.android.com/training/animation/screen-slide.html

http://developer.android.com/training/implementing-navigation/lateral.html

-

: Android - 2

, 2 . , , . "" , . , Android . .

+14

5 , ... 1 , .., , , layout_right , ... layout_right menu_layout... ... , ,

:

private void slide(final View v) {
    if (v.getLeft() != 0) {
        Animation toLeft = new TranslateAnimation(v.getRight() - 72, 0, 0, 0);
        toLeft.setDuration(animDuration);
        toLeft.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.clearAnimation();
                RelativeLayout.LayoutParams params = (LayoutParams) v
                        .getLayoutParams();
                params.leftMargin = 0;
                params.rightMargin = 0;
                v.setLayoutParams(params);
            }
        });
        v.startAnimation(toLeft);
    }
    else {
        Animation toRigh = new TranslateAnimation(0, -v.getWidth() - 72, 0, 0);
        toRigh.setDuration(animDuration);
        toRigh.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.clearAnimation();
                RelativeLayout.LayoutParams params = (LayoutParams) v
                        .getLayoutParams();
                params.leftMargin = (int) -(v.getWidth() - v.getWidth() * .15f);
                params.rightMargin = (int) (v.getWidth() * .85f);
                v.setLayoutParams(params);
            }
        });
        v.startAnimation(toRigh);
    }
}

private void slideBack(final View v) {
    if (v.getLeft() != 0) {
        Animation toLeft = new TranslateAnimation(-v.getLeft(), 0, 0, 0);
        toLeft.setDuration(animDuration + 100);
        toLeft.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.clearAnimation();
                RelativeLayout.LayoutParams params = (LayoutParams) v
                        .getLayoutParams();
                params.leftMargin = 0;
                params.rightMargin = 0;
                v.setLayoutParams(params);
            }
        });
        v.startAnimation(toLeft);
    }
}


@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        xPos = (int) event.getX();
    }

    if (event.getAction() == MotionEvent.ACTION_MOVE) {
        RelativeLayout.LayoutParams params = (LayoutParams) v.getLayoutParams();
        if (params.rightMargin + 1 > 0) {
            params.leftMargin = (int) (event.getRawX() - xPos);
            params.rightMargin = (int) (-event.getRawX() + xPos);
            v.setLayoutParams(params);
        }
    }
    if (event.getAction() == MotionEvent.ACTION_UP) {
        RelativeLayout.LayoutParams params = (LayoutParams) v.getLayoutParams();
        if (params.rightMargin < v.getWidth() / 2) {
            params.leftMargin = 0;
            params.rightMargin = 0;
        }
        else {
            params.leftMargin = (int) -(v.getWidth() - v.getWidth() * .15f);
            params.rightMargin = (int) (v.getWidth() * .85f);
        }

        v.setLayoutParams(params);
    }
    return true;
}

}

-1

All Articles