gpt4 book ai didi

android - Android 的边框手势

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:13:51 26 4
gpt4 key购买 nike

我正在开发一个应用程序(在 Galaxy Nexus 上),我注意到当您从边框底部滑动到屏幕上时,Google 实现了“Google Now”应用程序(Chrome 浏览器也这样做了同时,不确定它是否仍然如此)。我一直在四处寻找,但一直无法确定他们是如何做到这一点的。有没有一种简单的方法来处理从边框开始而不是从屏幕开始的手势?

我查看了开发者页面以供引用,但我能找到的唯一文章是:

http://developer.android.com/design/patterns/gestures.html

是否还有其他地方可以获得此信息?

[编辑]

我一直在尝试根据 Lain_B 的方法使边缘手势工作,但没有成功,但无法使其工作。这是我用来尝试检测手势的代码,但 logcat 始终输出零...

public class MainActivity extends Activity implements OnGestureListener {

private GestureDetector myGesture;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

myGesture = new GestureDetector(getBaseContext(),
(OnGestureListener) this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
Log.e("Flags Touch", "Flags: " + event.getEdgeFlags());
return myGesture.onTouchEvent(event);
}

@Override
public boolean onDown(MotionEvent e) {
Log.e("Flags", "Flags: " + e.getEdgeFlags());
Log.e("Event", "onDown");
// TODO Auto-generated method stub
return false;
}

@Override
public void onLongPress(MotionEvent e) {
Log.e("Event", "onLongPress");
// TODO Auto-generated method stub

}

@Override
public void onShowPress(MotionEvent e) {
Log.e("Flags", "Flags: " + e.getEdgeFlags());
Log.e("Event", "onShowPress");
// TODO Auto-generated method stub

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
Log.e("Event", "onSingleTapUp");
// TODO Auto-generated method stub
return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// Log.e("Event", "onScroll");
return false;
}

// these constants are used for onFling
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {

Log.e("Event", "onFling");
Log.e("Flags", "Flags: " + e1.getEdgeFlags());

if (e1.getEdgeFlags() == MotionEvent.EDGE_LEFT) {
// code to handle swipe from left edge
Log.e("!!!!!", "Edge fling!");
}

try {
// do not do anything if the swipe does not reach a certain length
// of distance
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;

// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {

}
// left to right swipe
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {

}
} catch (Exception e) {
// nothing
}
return false;

}
}

[编辑 2]

有了 Lain_B 请求的输出...

(使用 Nexus 7)...从边框上最左边的点开始,然后向右滑动到中间(大概)。

08-16 16:44:13.674: I/Fling(16702): Flags: 0
08-16 16:44:13.674: I/Fling(16702): e1: 2.5 711.5152
08-16 16:44:13.674: I/Fling(16702): e2: 215.4591 717.08105

从屏幕中心点滑动,离开屏幕(向右)

08-16 16:46:37.364: I/Fling(16702): Flags: 0
08-16 16:46:37.364: I/Fling(16702): e1: 392.5 758.1818
08-16 16:46:37.364: I/Fling(16702): e2: 783.4375 743.3334

最佳答案

我认为MotionEvent.getEdgeFlags()是你要找的。然后您可以将返回值与 EDGE_LEFT 进行比较, EDGE_RIGHT 等以查看触摸了哪条边。

if( event1.getEdgeFlags()&MotionEvent.EDGE_LEFT != 0 ){
//code to handle swipe from left edge
}

if( e1.getX() < 5.0f ){
//handle swipe from left edge
}

关于android - Android 的边框手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11970491/

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