Scrollview嵌套EditText,使其滑动
2016-03-12 15:29
295 查看
<ScrollView android:id="@+id/sv_scrollview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fadingEdge="none" android:scrollbars="none" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <cn.ls.widget.ScrollviewEdit android:id="@+id/sv_feedback" android:layout_width="fill_parent" android:layout_height="100dip" android:layout_gravity="center" android:fadingEdge="none" android:scrollbars="none" android:visibility="visible" > <LinearLayout android:layout_width="fill_parent" android:layout_height="100dip" android:gravity="center" android:scrollbars="vertical" > <EditText android:id="@+id/et_feedback" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="13dip" android:layout_marginRight="13dip" android:clickable="true" android:enabled="false" android:focusable="false" android:gravity="top" android:scrollbars="vertical" android:singleLine="false" android:background="@null" android:text="" /> </LinearLayout> </cn.ls.widget.ScrollviewEdit> </LinearLayout> </ScrollView>
这里是自定义的Scrollview,当然你也可以使用原生的。
因为我的整个页面是在一个Scrollview中,所以这又涉及到Scrollview嵌套Scrollview的问题,所以需要屏蔽父级的Scrollview.
public class ScrollviewEdit extends ScrollView {
private static final String TAG = "ScrollviewEdit";
private ScrollView parent_scrollview;
public ScrollView getParent_scrollview() {
return parent_scrollview;
}
public void setParent_scrollview(ScrollView parent_scrollview) {
this.parent_scrollview = parent_scrollview;
}
public ScrollviewEdit(Context context) {
super(context);
}
public ScrollviewEdit(Context context, AttributeSet attrs) {
super(context, attrs);
}
int currentY;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
LogUtils.i(TAG, "onInterceptTouchEvent--------");
if (parent_scrollview == null) {
return super.onInterceptTouchEvent(ev);
} else {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
// 将父scrollview的滚动事件拦截
currentY = (int) ev.getY();
setParentScrollAble(false);
LogUtils.i(TAG, "将父scrollview的滚动事件拦截-----");
return super.onInterceptTouchEvent(ev);
} else if (ev.getAction() == MotionEvent.ACTION_UP) {
// 把滚动事件恢复给父Scrollview
setParentScrollAble(true);
LogUtils.i(TAG, "把滚动事件恢复给父Scrollview-----");
} else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
}
}
return super.onInterceptTouchEvent(ev);
}
/**
* 是否把滚动事件交给父scrollview
* @param flag
*/
private void setParentScrollAble(boolean flag) {
parent_scrollview.requestDisallowInterceptTouchEvent(!flag);
}
}
其中private ScrollView parent_scrollview; 代表传递过来的父级Scrollview.
相关文章推荐
- Redis批量删除key
- Redis批量删除key
- SRTM数据介绍与说明
- CodeForces 630G:Challenge Pennants【排列组合】
- Mac开发Group Containers前缀问题
- Android获取App的版本名称和版本号
- 小组项目需求调查结果的分析
- python 字符串介绍
- mac安装IPython notebook以及scikit-image
- 所遇问题解决
- LeetCode 53 Maximum Subarray
- 我爱学Java之Map操作详解
- 100. Same Tree
- Linux下Java Web服务器搭建(YUM配置)
- Kmp算法
- 敏捷开发之Scrum扫盲篇
- 下载android源码
- 数据库设计三大范式
- 【Java】容器类学习之路(一)——综述
- android学习笔记——天气APP的尝试