NestedScrollView和EditText控件的滚动冲突问题
来源:互联网 发布:腾讯云 香港 cn2 知乎 编辑:程序博客网 时间:2024/06/14 05:15
NestedScrollView包裹EditText的时候会把子控件的滚动焦点抢掉了,所有EditText就不能滚动了,
解决思路:自定义一个EditText控件,在里面把父控件抢夺事件去掉就可以了。这样只会在EditText控件范围就会滚动EditText,其它范围就让ScrollView滚动。代码如下:
public class MyEditText extends EditText { public MyEditText(Context context) { super(context); } public MyEditText(Context context, AttributeSet attrs) { super(context, attrs); } public MyEditText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public boolean onTouchEvent(MotionEvent ev) { getParent().requestDisallowInterceptTouchEvent(true); return super.onTouchEvent(ev); }}
代码XML的布局代码如下:
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <com.elife.pocketassistedpat.ui.view.MyEditText android:id="@+id/et_content" android:layout_width="match_parent" android:layout_height="160dp" android:background="@color/white" android:gravity="top" android:hint="请描述错误的地方" android:imeOptions="actionDone" android:scrollbars="vertical" android:padding="12dp" android:paddingTop="16dp" android:textColor="@color/c_323232" android:textColorHint="@color/c_a2a2a2" android:textSize="@dimen/sp_16" /> <android.support.v7.widget.RecyclerView android:id="@+id/rv_imgs" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" android:overScrollMode="never" android:padding="12dp" /> <TextView android:id="@+id/btn_complete" style="@style/My_btn" android:layout_marginTop="40dp" android:layout_marginRight="20dp" android:layout_marginLeft="20dp" android:textSize="16dp" android:textColor="@color/white" android:text="提交" /> </LinearLayout> </android.support.v4.widget.NestedScrollView>
阅读全文
0 0
- NestedScrollView和EditText控件的滚动冲突问题
- ScrollView和EditText的滚动冲突问题
- 支持嵌套滚动的控件NestedScrollView
- NestedScrollView 中的 EditText 问题
- EditText和ScrollView滚动冲突
- 完美解决EditText和ScrollView的滚动冲突(上)
- 完美解决EditText和ScrollView的滚动冲突(下)
- EditText监听输入完成和设置点击事件时与父控件的冲突问题
- ListView中使用EditText(解决EditText焦点丢失、保存数据以及滚动冲突的问题)
- 解决NestedScrollView 嵌套 RecyclerView出现的滑动冲突问题
- GridView+NestedScrollView 滑动冲突问题的两种解决方法
- Android之NestedScrollView 嵌套 RecyclerView 滑动冲突的问题
- ViewPager与NestedScrollView套嵌会引起冲突,滑动不了的问题
- NestedScrollView+RecyclerView优雅的解决滑动冲突问题
- NestedScrollView+RecyclerView优雅的解决滑动冲突问题
- 关于WebView和NestedScrollView奇奇怪怪的问题
- 关于WebView和NestedScrollView奇奇怪怪的问题
- editText 滚动事件和长按事件冲突
- JSON详解
- Cardboard实现VR的目选效果
- 判断Integer值相等用equals
- Ch02
- 如何使用CrudRepository<T, ID extends Serializable> extends Repository<T, ID>
- NestedScrollView和EditText控件的滚动冲突问题
- art-template常用总结
- View[0] measure
- java导出包含多个sheet的Excel
- 干货
- dede织梦技巧:教你彻底解决dede按权重排序的问题
- 分库分表
- Hadoop 和 Spark 的异同
- 接口测试