滚动型内多个滚动TextViews [英] Multiple Scrollable TextViews inside a ScrollView

查看:170
本文介绍了滚动型内多个滚动TextViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动型包含一个复杂的的LinearLayout 的各种元素,其中有几个的TextView 与定义了maxHeight和长文本中。我需要启用滚动里面的的TextView 时,触摸和拖拽里面,和正常滚动的滚动型当触摸拖动它们之外。

I have a ScrollView that contains a complex LinearLayout with various elements, among which there are several TextView with maxHeight defined and a long text inside. I need to enable scrolling the text inside the TextView when touch-and-dragging inside it, and the normal scroll of the ScrollView when touch-and-drag outside of them.

是否有适当的和优雅的方式来做到这一点 - 如果在所有可能的 - 或者说我变脏,并开始覆盖所有元素的onTouchEvent 处理程序参与?

Is there a proper and elegant way to do this - if at all possible - or do I have to get dirty and start overriding the onTouchEvent handlers on all elements involved?

UPD 1:这个来看,没有优雅的解决方案,而UI将不得不rethinked包括只有一层可滚动的元素。

UPD 1: Judging from this there is no elegant solution, and the UI will have to be rethinked to include only one layer of scrollable elements.

推荐答案

因此​​,它不是pretty的,但你可以从TextView的延伸和滚动块滚动视图。这不是因为漂亮,除非你textviews足够大。使用此解决方案后,我们发现,这是最好的,如果你有一个显示更多标签的用户可以点击可显示完整的东西。无论如何,从TextView的延伸和覆盖的onTouchEvent方法:

So it's not pretty, but you can extend from TextView and block the scrollview from scrolling. It's not as nice unless your textviews are large enough. After using this solution we found that it is best if you have a "show more" label that the users can click to show the full thing. Anyway, extend from TextView and override the onTouchEvent method:

  public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
      this.getParent().requestDisallowInterceptTouchEvent(true);
    }
    if (ev.getAction() == MotionEvent.ACTION_UP) {
      this.getParent().requestDisallowInterceptTouchEvent(false);
    }

    return super.onTouchEvent(ev);
  }

这篇关于滚动型内多个滚动TextViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆