如何让 Activity 使用 ScrollView 并保持 onTouch 方法正常工作?

发布于 2024-10-27 22:50:13 字数 382 浏览 10 评论 0原文

我有一个 Activity,它在 ViewFlipper 上填充两个视图。我向 Activity 添加了一个 onTouch(View v, MotionEvent event) 公共布尔方法。该方法的实现是为了当用户点击屏幕时 ViewFlipper 转到下一个视图。它工作得很好,但有些文本太长,所以我进入了 XML 文件,并用线性布局和 ScrollView 包围了我的 ViewFlipper 视图之一中的文本字段。但是现在当我查看太长并显示滚动条的字段时,我无法显示以前的视图。我的主要活动中的 onTouch 方法没有被执行。我一直无法弄清楚这一点。我读过一些关于实现或重写 ScrollView 中的方法的文章,但我不知道在我的活动中在哪里执行此操作。有谁知道我如何对 ScrollView 进行编程以使其不拦截但保持其滚动视图的能力?

I have an Activity that populates two views on a ViewFlipper. I added an onTouch(View v, MotionEvent event) public boolean method to the Activity. The method is implemented so that when the person taps on the screen the ViewFlipper goes to the next view. It works great but some of the text is too long so I went into my XML file and surrounded the textfield in one of my ViewFlipper views with a linearlayout and then a ScrollView. But now when I'm viewing the fields that are too long and show a scroll bar, I can't display the previous view. The onTouch method in my main activity isn't being executed. I have not been able to figure this out. I've read some posts about implementing or overriding the methods in ScrollView but I don't know where to do this in my activity. Does anyone know how I can program ScrollView to not intercept but keep its ability to scroll the view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飞烟轻若梦 2024-11-03 22:50:13

ScrollView myScroll;
myScroll.setOnTouchListener(new OnTouchListener){

  @Override
  public boolean onTouch(View v, MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        oldTouchValue = touchevent.getX();
        break;
    }
    case MotionEvent.ACTION_UP: {
        float currentX = touchevent.getX();
        if (oldTouchValue < currentX) {
                       //left swipe
                       return true;

                     }
                     if (oldTouchValue > currentX) {
                       //right swipe
                       return true;
                     }

               return false;

  }

}

ScrollView myScroll;
myScroll.setOnTouchListener(new OnTouchListener){

  @Override
  public boolean onTouch(View v, MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        oldTouchValue = touchevent.getX();
        break;
    }
    case MotionEvent.ACTION_UP: {
        float currentX = touchevent.getX();
        if (oldTouchValue < currentX) {
                       //left swipe
                       return true;

                     }
                     if (oldTouchValue > currentX) {
                       //right swipe
                       return true;
                     }

               return false;

  }

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文