Android ScrollView嵌套ScrollView滚动的问题解决办法
2014-04-24 21:34
253 查看
引用: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;
}
});
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;
}
});
相关文章推荐
- Android ScrollView嵌套ScrollView滚动的问题解决办法
- Android ScrollView嵌套ScrollView滚动的问题解决办法
- ListView smoothScrollToPositionFromTop 偶现滚动位置不精确问题解决办法
- ScrollView嵌套可以水平滚动的自定义控件时滑动事件冲突问题解决办法
- Android ScrollView嵌套ScrollView滚动的问题解决办法
- 在ScrollView添加一个ListView造成的滚动问题的简单解决办法()
- Android ScrollView嵌套ScrollView滚动的问题解决办法
- Android ScrollView嵌套ScrollView滚动的问题解决办法
- 在ScrollView添加一个ListView造成的滚动问题的简单解决办法
- 在ScrollView添加一个ListView造成的滚动问题的简单解决办法
- RecyclerView 调用notifyDataSetChanged()方法刷新后 自动滚动到顶部 问题解决办法
- Android ScrollView嵌套ScrollView滚动的问题解决办法
- MFC重写OnCtlColor函数造成的文本框文字、闪烁重叠的问题解决办法
- redmine svn:issuer is not trusted 问题的解决办法
- ie6 表格tr不兼容border问题及解决办法
- 问题 error C2065: '_beginthreadex' : undeclared identifier 的解决办法
- linux下由于系统编码问题造成乱码的解决办法
- UIScrollView无法滚动可能的原因及解决办法分析
- ionic 之cordova 极光推送jpush和百度定位插件结合使用之定位失效问题解决办法
- ssh 速度慢的问题另外一种解决办法