Horizontal swiping in stackview

大城市里の小女人 提交于 2019-12-09 07:00:15

问题


I am in an app which requires stackview. But I have to implement horizontal swiping to switch between stackview items and UI looks as that of as normal one. Please help me to make it.

I have already checked this link.

But in it UI is just a cover flow. I want to make the UI look same as stackview.


回答1:


iam create a custom stack-view

  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;
    }

}

use as

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



回答2:


I do not give source code but i think this link help

http://docs.huihoo.com/android/3.0/resources/samples/StackWidget/

http://www.broculos.net/2011/12/android-101-how-to-create-stackview.html#.UrmOoPuJQ8Y

Thanks




回答3:


Recently came across a great little hack for this. In your layout XML use:

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

Then within the item's XML:

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

You can play with the numbers to change the direction however you need.



来源:https://stackoverflow.com/questions/20761944/horizontal-swiping-in-stackview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!