Android:如何在活动(非片段)之间滑动,掌握/详细设置最佳设置 [英] Android: How to swipe between activities (not fragments), master/detail best set-up

查看:123
本文介绍了Android:如何在活动(非片段)之间滑动,掌握/详细设置最佳设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android应用程序,而对于包括移动应用程序开发在内的所有应用程序我都是新手,所以我有几个问题.任何帮助都将是惊人的!

I'm working on an android app and I'm fairly new to all this, including mobile app development, so I have a few questions. Any help would be amazing!

1)是否可以在整个活动(包括动作栏)之间滑动?我的意思不是像viewPager在片段之间交换,而是在交换整个屏幕(就像iOS上的snapchat一样).这有可能吗?如果是这样,我该怎么办?

1) Is it possible to swipe between entire activities (including action bar)? And I don't mean like viewPager swapping between fragments, I mean swapping the entire screen (like snapchat does on iOS). Is this possible at all? And if so, how can I do this?

2)实施主/详细类型布局的最佳方法是什么?像推特例如,如果我有一条tweets的listView,并且当某人单击某个该推文将带您详细了解该特定的推文...这将是什么最好的方法来做到这一点?我是否可以进行带有列表视图的活动并创建点击推文后的第二项活动?还是我用片段代替用于列表视图,一个用于详细视图?

2) What is the best way to implement a master/detail type layout? Like twitter for instance, if i have a listView of the tweets, and when a person clicks on a tweet it takes you to a detailed view of that specific tweet... What would be the best way to accomplish this? Would I have an activity with a list view and create a second activity upon clicking on a tweet? Or would I use fragments instead, one for the list view and one for the detailed view?

3)是否可以为每个片段设置不同的操作栏?

3) Is there a way to have different action bars for every fragment?

非常感谢你!

推荐答案

可以刷卡:

OnTouchSwipeListener

OnTouchSwipeListener

import android.content.Context;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class OnSwipeTouchListener implements OnTouchListener {



private final GestureDetector gestureDetector;
private Context context;

/* (non-Javadoc)
 * @see android.view.View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent)
 */
public boolean onTouch(final View view, final MotionEvent motionEvent) {
    return gestureDetector.onTouchEvent(motionEvent);
}

/**
 * Gets the gesture detector.
 * 
 * @return the gesture detector
 */
public GestureDetector getGestureDetector(){
    return  gestureDetector;
}

/**
 * Instantiates a new on swipe touch listener.
 * 
 * @param context
 *            the context
 */
public OnSwipeTouchListener(Context context) {
    super();
    this.context = context;
    gestureDetector = new GestureDetector(context, new GestureListener());
}

private final class GestureListener extends SimpleOnGestureListener {

    private static final int SWIPE_THRESHOLD = 100;
    private static final int SWIPE_VELOCITY_THRESHOLD = 100;

    /* (non-Javadoc)
     * @see android.view.GestureDetector.SimpleOnGestureListener#onDown(android.view.MotionEvent)
     */
    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }

    /* (non-Javadoc)
     * @see android.view.GestureDetector.SimpleOnGestureListener#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)
     */

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        boolean result = false;
        try {
            float diffY = e2.getRawY() - e1.getRawY();
            float diffX = e2.getRawX() - e1.getRawX();
            if ((Math.abs(diffX) - Math.abs(diffY)) > SWIPE_THRESHOLD) {
                if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                    if (diffX > 0) {
                        onSwipeRight();
                    } else {
                        onSwipeLeft();
                    }
                }
            } else {
                if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                    if (diffY > 0) {
                        onSwipeBottom();
                    } else {
                        onSwipeTop();
                    }
                }
            }
        } catch (Exception e) {

        }
        return result;
    }
}

/**
 * On swipe right.
 */
public void onSwipeRight() {
}

/**
 * On swipe left.
 */
public void onSwipeLeft() {
}

/**
 * On swipe top.
 */
public void onSwipeTop() {
}

/**
 * On swipe bottom.
 */
public void onSwipeBottom() {
}
}

实施:

OnSwipeTouchListener onSwipeTouchListener = new OnSwipeTouchListener(Activity.this) {
        @Override
        public void onSwipeLeft() {
            //your actions
        }
    };

这篇关于Android:如何在活动(非片段)之间滑动,掌握/详细设置最佳设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆