任何人都可以举例说明如何在android中的webview中实现手势检测器
谢谢
我有一个对话框来选择文件.此对话框包含用于显示目录和文件的列表视图,并具有用于导航目的的onItemClickListener.
如何对目录结构中的fling事件做出反应?我尝试在根RelativeLayout上设置一个OnTouchListener来将触摸事件分派给我的GestureListener:
final GestureDetector detector = new GestureDetector(new MyGestureDetector(tvCurrentPath));
dialog.findViewById(R.id.rlFilelist).setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent e) {
detector.onTouchEvent(e);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
事件在onTouch()中注册,但onFling()方法永远不会在MyGestureDetector中调用.但是,如果我将OnTouchListener附加到列表视图,它将按预期工作.这种方法的问题在于listview并不总是充满数据,当它是空的或点击下面的项目时,没有触发onTouch()事件.
对话框布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlFilelist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:focusable="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/llButtons" >
<TextView
android:id="@+id/tvCurrentPath"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" >
</TextView>
<ListView
android:id="@+id/lvFileListing"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/llButtons"
android:layout_below="@id/tvCurrentPath" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/llButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip" >
<Button
android:id="@+id/btAddDirectory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10px"
android:text="@string/host_tv_dg_add_directory" />
<Button
android:id="@+id/btUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px" …Run Code Online (Sandbox Code Playgroud) 我尝试创建一个应用程序,当用户点击屏幕上的任何地方时,该应用程序将背景颜色更改为随机颜色,但 OnTap 功能仅在我点击文本时才起作用。请帮助我如何解决它。
这是我的代码:
import 'package:flutter/material.dart';
import 'dart:math';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MainVidget();
}
}
class MainVidget extends StatefulWidget {
@override
MainVidgetState createState() => MainVidgetState();
}
class MainVidgetState extends State<MainVidget> {
Color mainColor = Colors.white;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
backgroundColor: mainColor,
appBar: AppBar(
title: Text('Tap anywhere'),
),
body: GestureDetector(
onTap: () {
setState(() {
mainColor = Color.fromRGBO(Random().nextInt(254) + 1,
Random().nextInt(254) …Run Code Online (Sandbox Code Playgroud) 我有一个由多个路径组成的 SVG。我想要一个onTap监听器 - 可能使用 aGestureDetector并找出用户(按类)点击了哪条路径。
我已经尝试了几种方法:
我的 webview 方法在这里有效,我正在接收点击事件和我可能想要的任何信息,但我想要一个更清晰的解决方案,我想一些本机应该支持做我想做的事情。
这是SVG的一个片段:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 670.95 321.09">
<g id="part_one">
<path stroke="#333" fill="#f8be16" class="piece_one" d="M143.71,155s8,27.34,8.24,30c6.38.19,43.38,0,43.38,0s1.49-58.68,2.86-61.93-15.62,7.13-24.12,7.13H142.19Z" transform="translate(-5.55 -0.06)"/>
<path stroke="#333" fill="#c5ca15" class="piece_two" d="M171.19,158.63a7.46,7.46,0,0,0-4.68,9.45l.06.18c1.13,2.25,4.88,5.63,9.13,3.75,3.63-1.6,4.54-6.5,3-9.5S173.08,157.88,171.19,158.63Z" transform="translate(-5.55 -0.06)"/>
</g>
<g id="part_two">
<path stroke="#333" fill="#c67d3e" class="piece_three" d="M226.85,207.63s3.9,44.48,5.65,48.56-26.41,9.76-34.75,10.13A112,112,0,0,1,179,265s2.85-58.21,2.63-61.46C200.32,206.13,204.74,206.55,226.85,207.63Z" transform="translate(-5.55 -0.06)"/>
<path stroke="#333" fill="#c2c6b2" class="piece_one" d="M198.19,123.13s-4.68,28.63-3.78,36.25,1.83,25.75,1.83,25.75,29.43,2.75,30.56,1.63.26-23.62,2.88-31.12,10.5-23.25,10.5-23.25-19.25-.37-25.5-3.87S202.32,122.5,198.19,123.13Z" transform="translate(-5.55 -0.06)"/>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
我可以工作第三种解决方案现在,但是看这是对所看到的荷兰地图实现的解决方案在这里,我期待着找到这个土生土长的解决方案。目前我正在查看CustomPainter文档,因为我觉得这会涉及到。
我感谢任何输入和/或帮助!
我在使用ScrollView和时遇到了一些事件处理问题Transform。布局结构是这样的,ScrollView并且Transform存在于Stack.
我希望在inScrollView之外滚动时滚动,事件可以渗透到 ScrollView。FlatButtonContainer(Colors.cyan)
单击按下FlatButton即可工作。实际上,单击FlatButton两次后,无论单击初始位置还是当前位置,它都不再移动。该FlatButton控制移动从尺寸范围内的初始位置离开,不再检测到点击事件,但我不明白。代码如下:
class EventListener extends StatefulWidget {
@override
_EventListenerState createState() => _EventListenerState();
}
class _EventListenerState extends State<EventListener> {
Offset offset = Offset(0, 0);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("EventListener"),
),
body: Stack(
children: <Widget>[
SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
color: Colors.red,
height: 200,
),
Container(
color: Colors.teal,
height: 300,
),
Container(
color: …Run Code Online (Sandbox Code Playgroud) 任何人都会有一个在 Monodroid 中使用 GestureListner 的工作示例吗?我似乎无法使用 Java 成功翻译网络上的内容。
我想我很接近......而且我想如果我能让这个“OnTouchEvent”触发,我可以反过来让我的 GestureDetector 类的 OnTouchEvent 触发,然后我就能获得滑动动作(或 OnFling) .
我需要做什么才能在我的 Activity 类中触发此事件?不
public override bool OnTouchEvent(MotionEvent e)
{
m_gestureDetector.OnTouchEvent(e);
return base.OnTouchEvent(e);
}
Run Code Online (Sandbox Code Playgroud)
而且我认为我绝对需要 OnTouch 事件而不是 OnClick,因为我需要 MotionEvent。
当用户按下按钮时,我需要执行方法,换句话说,在按下操作过程中,用户将按下按钮不知道的时间段。在这段时间内,我需要执行方法,任何人都知道我该怎么做Flutter我尝试了GestureDetector,但是没有选项可以做到,onLongPress也没有此选项,因为在按长按操作后触发的长按触发了,我将为我需要的内容编写伪代码:
While(Button.isPressed){
//Execute Method
}
Run Code Online (Sandbox Code Playgroud) 例如:
// Update: This GestureDetector is embedded inside a third party package
// that will invoke a series of animation along with the onTap button
GestureDetector(
onTap: () => print('Hey There!'),
child: Widget1(),
)
// Then another place in the same screen
GestureDetector(
onDoubleTap: () {
//Call the onTap of Widget1's GestureDetector
print('I'm Here');
}
child: Widget2(),
)
Run Code Online (Sandbox Code Playgroud)
我想是当用户双击Widget2时,也会调用onTap的回调Widget1。
更新:所以我不想只调用传递给onTapofGestureDetector的函数Widget1,而是以编程方式点击onTapWidget1 的GestureDetector
我怎么做?
我正在构建一个可以向上/向下滑动以改变其高度的底板。我希望其内部子组件可滚动,但它无法按预期工作。我只是猜测其原因是任何触摸事件(例如滚动)ScrollView都会被捕获并冒泡,GestureDetector因此滚动内部内容不起作用,而滑动工作表本身却起作用。
import { Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
import React, { useCallback, useEffect } from 'react';
import Animated from 'react-native-reanimated';
import {
Gesture,
GestureDetector,
ScrollView,
} from 'react-native-gesture-handler';
import {
Extrapolate,
interpolate,
useAnimatedStyle,
useSharedValue,
withSpring,
} from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useHeaderHeight } from '@react-navigation/elements';
const { height: SCREEN_HEIGHT } = Dimensions.get('window');
type Props = {
top: number;
bottom: number;
initialBottomOffset: number;
};
export const BottomSheet: React.FC<Props> = ({
children, …Run Code Online (Sandbox Code Playgroud) android gesturedetector react-native react-native-reanimated-v2
背景
尝试设置一个简单的图像编辑器,允许用户通过手势缩放和移动图像。
GestureDetector通过,Transform.scale和可以很好地进行缩放和移动Transform.rotate。
问题
缩放后,用户仍然可以缩放已经缩放的图像。
但是:这GestureDetector不会改变执行命中测试的区域。
问题:用户只能使用原始的 hitbox 来操作图像。无法通过在扩展的外部形状上使用两指捏合手势来缩放图像。
图片
第一张图片演示了基本设置。
第二张图片演示了使用手势的结果。它显示了小的、未改变的内部碰撞箱。以及由此产生的缩放和旋转形状。
填充的框是碰撞框。外部矩形显示缩放后的图像。
期望的行为
在缩放后的外部形状上使用两指捏合手势应该允许进一步操作对象。
相反,内部打击盒可以单独使用。但用户期望使用缩放后的外部形状来进一步缩放和移动对象。
代码
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: GestureTest(),
);
}
}
class DrawContainer {
Color color;
Offset offset;
double scale;
double angle;
late double baseScaleFactor;
DrawContainer(this.color, this.offset, this.scale, this.angle) {
baseScaleFactor = scale;
}
onScaleStart() => …Run Code Online (Sandbox Code Playgroud) gesturedetector ×10
flutter ×6
android ×5
onfling ×2
transform ×2
button ×1
dialog ×1
gesture ×1
react-native ×1
svg ×1
touch-event ×1