我的问题很简单,实现GestureListener时onUp事件在哪里?
我在gesturedetector上有很多事件,并且不能只使用侦听器的onUp事件,因为其中一个事件是需要它的onSingleTapConfirmed.
当他停止拖放我的RecyclerView时(当他放下所选项目时),我需要听取用户的意见.
我可以通过我的ItemTouchHelper获取此信息吗?
谢谢你的帮助
马克:目前我只是在用户仍然移动项目的时候:)
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
if (source.getItemViewType() != target.getItemViewType()) {
return false;
}
// Notify the adapter of the move
mAdapter.onItemMove(source.getAdapterPosition(), target.getAdapterPosition());
return true;
}
Run Code Online (Sandbox Code Playgroud) 我有两个容器,两个容器都有GestureDetector。第一个容器的OnTap工作正常,但不能与另一个容器一起使用。第一个容器是图像,第二个容器是部分在第一个容器上对齐的绿色背景。
new Stack(
alignment: Alignment(0.0, 1.44),
children: <Widget>[
GestureDetector(
onTap: () => _openImage(context),
child: Container(
width: 340.0,
foregroundDecoration: new BoxDecoration(
color: Color.fromRGBO(155, 85, 250, 0.55)),
height: 240.0,
child: FadeInImage.assetNetwork(
placeholder: 'assets/dimlight.png',
image: post.imageUrl,
fit: BoxFit.cover,
),
),
),
new GestureDetector(
child: new Container(
color: Colors.green,
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
SizedBox(width: 7.0),
CircleAvatar(
backgroundImage:
new AssetImage("assets/boy.png")
radius: 30.0,
),
SizedBox(
width: 7.0,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new SizedBox(
height: 20.0,
),
Text(
post.user.name,
style: TextStyle(fontWeight: FontWeight.bold),
), …
Run Code Online (Sandbox Code Playgroud) 在我的GestureDetector中使用LongPress后,如何收听移动事件?
当用户LongClick他启动选择模式时,可以将一个方块拖入屏幕.但我注意到在使用LongPress后没有调用onScroll.
我有以下ListActivity:
public class ShowDayActivity extends ListActivity implements OnItemClickListener {
private GestureDetector gestureDetector;
private View.OnTouchListener gestureListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.day);
registerForContextMenu(getListView());
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
getListView().setOnItemClickListener(this);
getListView().setOnTouchListener(gestureListener);
}
@SuppressWarnings("static-access")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
...
return super.onOptionsItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
...
return super.onContextItemSelected(item);
}
Override
public void onItemClick(AdapterView<?> parent, View v, int pos, long …
Run Code Online (Sandbox Code Playgroud) 我刚开始在Android中编写自定义视图(第一次),我意识到我需要实现滚动功能.
自定义视图还使用包含一些文本的标题(应该保持固定而不是滚动).
我已经阅读了关于GestureDetector.SimpleOnGestureListener
和的文档Scroller
.我还阅读了关于动画滚动手势的文档,但我发现这些示例很难理解.我还看了Stack Overflow上的其他一些问题.
使用我在Stack Overflow答案的文档中理解的作为参考来指导我,我已将以下内容添加到我的自定义视图中:
变量和字段:
private OverScroller mScroller;
private final GestureDetector mGestureDetector =
new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// Note 0 as the x-distance to prevent horizontal scrolling
scrollBy(0, (int) distanceY);
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
final int maxScrollX = 0;
// wholeViewHeight is height of everything that …
Run Code Online (Sandbox Code Playgroud) 我嵌套了GestureDetetor
s 但问题是只有 childGestureDetector
被onTap
执行。我不想覆盖孩子的 onTap,而是希望父母和孩子的 onTap 都执行。这是我的代码:
GestureDetector(
onTap: () {
todo1();
},
child: GestureDetector(
onTap: () {
todo2();
},
child: Text("Nested Gesture")))
Run Code Online (Sandbox Code Playgroud)
如何更改它以同时调用onTaptodo1()
和todo2()
onTap?
编辑:子级是一个可重用的自定义小部件,它有自己的实现,但现在由父级使用,除了其子级之外,父级也有自己的实现
我有 3 个孩子的 TabBarView,其中一个我有一个带有onPanUpdate
手势的容器。
当我尝试移动容器选项卡栏onHorizontalDragUpdate
调用和选项卡栏更改选项卡而不是容器时。
如果我在 javascript 中像 stoppropagation 这样的容器上贴上胶带,有什么办法可以防止 onHorizontalDragUpdate 吗?
TabBarView(
controller: _tabController,
children: [
Container(
color: Colors.red,
),
TabWithDragableContainer(),
Container(
color: Colors.blue,
),
],
)
Run Code Online (Sandbox Code Playgroud) 我有一个RelativeLayout,中间有一个TextView.我已经使用SimpleOnGestureListener()来检测onFling,onDown和onScroll事件.
我希望TextView能够在屏幕上跟随我的手指(可以只是在x轴上),当我抬起手指时,它会从屏幕上移动或者回到中间(取决于我有多远)感动它).