我GestureDetector.OnGestureListener在 Activity 中实现,其覆盖的 onTouchEvent 是:
public boolean onTouchEvent(MotionEvent event) {
//gestureDetector is new GestureDetector(this,this) in Activity's onCreate()
this.gestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
使用 MotionEvent 类中的 getEdgeFlags 进行边缘检测,如下所示:
@Override
public boolean onDown(MotionEvent e) {
final int edgeInfo = e.getEdgeFlags();
return ((edgeInfo == MotionEvent.EDGE_LEFT) || (edgeInfo == MotionEvent.EDGE_RIGHT)) ||
(edgeInfo == MotionEvent.EDGE_BOTTOM);
}
Run Code Online (Sandbox Code Playgroud)
但是 onDown 总是返回 false。我也试过改变
final int edgeInfo = e.getEdgeFlags(); 到
final int edgeInfo = e.getAction() & e.getEdgeFlags();
以及final int edgeInfo = e.getActionMasked() & e.getEdgeFlags();以防万一。
却无济于事。
我看过 …
我正在编写一个非常基本的Home Launcher,我在AppsGridActivity中创建了一个类AppsInfoModel,一个CustomAdapter和一个GridView.
这是我在Activity中填充适配器的代码
appsGrid = (GridView) findViewById(R.id.appsGrid);
appsInfo = new AppsInfoModel(this);
appsGrid.setAdapter(new CustomAdapter(this,appsInfo));
Run Code Online (Sandbox Code Playgroud)
这是适配器
public class CustomAdapter extends BaseAdapter {
Context context;
AppsInfoModel appInfo;
CustomAdapter(Context context,AppsInfoModel appInfo) {
this.context = context;
this.appInfo = appInfo;
}
@Override
public int getCount() {
return appInfo.getSize();
}
@Override
public Object getItem(int position) {
return appInfo.getItem(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = ((Activity) …Run Code Online (Sandbox Code Playgroud)