引用:http://fenglog.com/article.asp?id=449
Android ScrollView嵌套ScrollView滚动的问题解决办法
原文地址:http://trivedihardik.wordpress.com/2011/09/19/scrollview-inside-scrollview-scrolling-problem/

搞技术的多少看的懂E文,也不翻译了。

While designing rich layouts you might need to use two scrollview in your app.
Well ideally its not advised to use two scrollview in a view. So try to avoid it.

Why this problem occurs ? :

When you put two scrollview android just get confused which scroll view is touched. So sometimes it gets unable to deliver touch event.

But even if the requirement forces you to make such layouts. Try this…

Say case is somewhat like this….

<ScrollView android:id=”@+id/parent_scroll”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:background=”@drawable/dotted_bg”
android:focusableInTouchMode=”false”>
<LinearLayout />
<LinearLayout />
<LinearLayout >
<ScrollView android:id=”@+id/child_scroll”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”@drawable/text_box_bg”>
<TextView android:id=”@+id/text_description”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:textColor=”@color/gray”
android:textSize=”12dip”
android:padding=”5dip”
android:scrollbars=”vertical”/>
<!–ScrollView>
</LinearLayout>
</ScrollView>

Step 1 : Provide unique id to both the scrollview.
Step 2 : get reference of that two scrollview in your activity.

parentScroll=(ScrollView)findViewById(R.id.parent_scroll);
childScroll=(ScrollView)findViewById(R.id.child_scroll);

Step 3: Now set touch listeners for both.

parentScroll.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
Log.v(TAG,”PARENT TOUCH”);
findViewById(R.id.child_scroll).getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScroll.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event)
{
Log.v(TAG,”CHILD TOUCH”);
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

Done …

更多相关文章

  1. 【Android与iOS开发对比系列】之 回调机制
  2. Android触摸事件传递机制及viewpager嵌套fragment冲突处理
  3. Android(安卓)中文 API (100) —— ScrollView
  4. android仿摩拜单车APP、炫酷RecyclerView、卡片滑动、仿饿了么点
  5. Android(安卓)build system
  6. Android(安卓)- listview未滚动触发onScroll
  7. android DIY 2
  8. ScrollView嵌套RecyclerView时只显示一行元素
  9. Android手势操作(双击,长按,滑动,滚动,多点触控)

随机推荐

  1. MEaaS,一个创新的云密码服务
  2. 反向代理服务器:为什么用,怎么用,如何用?
  3. Spark2.4.0屏障调度器
  4. DevOps究竟是什么?来看开发人员的观点
  5. 大数据啊大数据!
  6. 测试移动端网站兼容的九个工具
  7. 《2020年IT行业项目管理调查报告》重磅发
  8. FFmpeg-kkFileView音频服务安装
  9. 苹果Mac休眠唤醒后出现死机情况如何解决?
  10. Citrix XenDesktop7.15长期稳定版本虚拟