在stackview水平刷卡 [英] Horizontal swiping in stackview
本文介绍了在stackview水平刷卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个应用程序需要stackview。但我要实现水平刷卡到stackview项目之间切换和用户界面看起来是正常之一。请帮我做出来。
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.
我已经检查过这<一href="http://stackoverflow.com/questions/13956086/custom-horizontal-stackview-on-the-android-platform">link.
但它的用户界面是只是个幌子流。我想使用户界面看起来一样stackview。
But in it UI is just a cover flow. I want to make the UI look same as stackview.
推荐答案
IAM创建自定义堆栈视图
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;
}
}
作为
<package_name.custom_stackview
android:id="@+id/stackview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:loopViews="true"
/>
这篇关于在stackview水平刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文