gpt4 book ai didi

java - 在堆栈 View 中水平滑动

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:46:16 24 4
gpt4 key购买 nike

我在一个需要堆栈 View 的应用程序中。但是我必须实现水平滑动才能在堆栈 View 项目和 UI 之间切换,看起来就像普通的一样。请帮助我完成它。

我已经检查过这个 link .

但是里面的UI只是一个封面流程。我想让 UI 看起来和 stackview 一样。

最佳答案

我创建一个自定义堆栈 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"
/>

关于java - 在堆栈 View 中水平滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20761944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com