Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java stackview中的水平滑动_Java_Android_Android Ui_Stackview - Fatal编程技术网

Java stackview中的水平滑动

Java stackview中的水平滑动,java,android,android-ui,stackview,Java,Android,Android Ui,Stackview,我使用的应用程序需要stackview。但我必须实现水平滑动,以便在stackview项目和UI看起来与正常项目一样的情况下进行切换。请帮我做一下 我已经检查过了 但在it中,UI只是一个覆盖流。我希望使UI看起来与stackview相同。我可以创建自定义堆栈视图 public class custom_stackview extends StackView{ float x1, x2, y1, y2, dx, dy; public custom_stackview(Con

我使用的应用程序需要stackview。但我必须实现水平滑动,以便在stackview项目和UI看起来与正常项目一样的情况下进行切换。请帮我做一下

我已经检查过了


但在it中,UI只是一个覆盖流。我希望使UI看起来与stackview相同。

我可以创建自定义堆栈视图

  public class custom_stackview extends StackView{

    float x1, x2, y1, y2, dx, dy;
    public custom_stackview(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
    public custom_stackview(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        super.onTouchEvent(event);

        switch(event.getAction()) {
            case(MotionEvent.ACTION_DOWN):
                x1 = event.getX();
                y1 = event.getY();
                break;
           case(MotionEvent.ACTION_MOVE):
           case(MotionEvent.ACTION_UP) :{
            x2 = event.getX();
            y2 = event.getY();
            dx = x2 - x1;
            dy = y2 - y1;

            // Use dx and dy to determine the direction
            if (Math.abs(dx) > Math.abs(dy)) {
                if (dx > 0) {// direction = "right";
                    showNext();
                } else {

                    showPrevious();


                }

            }
            }
         // Log.v("hiiiiiiiiiii", direction+re);
        }
        return true;

    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stubLog.v("hiiiiiiiiiii","touched");
        Log.v("hiiiiiiiiiii","toucheddddddddd");
        //boolean re =false;


        return false;
    }

}
用作

 <package_name.custom_stackview
        android:id="@+id/stackview"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:loopViews="true"
        />

最近遇到了一个很好的小技巧。 在布局XML中,请使用:

<StackView
    android:animateLayoutChanges="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:rotation = "-90" />

然后在项目的XML中:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:rotation = "90" />


您可以根据需要使用数字来改变方向。

+1对于几乎完整的解决方案-我需要修复以下代码以便执行良好-删除
案例(MotionEvent.ACTION\u MOVE):
并添加
默认值:break,否则它会在移动\滑动时继续移动视图。