电话
400 9058 355
今天项目中需求是写出一个很简单的edittext输入框,但要求当输入字数过长时需要上下滑动以便查看所有文字,因为页面底部有一个"确定"的button,但刚开始输入框内的问题怎么都滑动不了,我一开始就想到了这是事件传递冲突问题,但试了很多种方法都不行,最后也是一个一个试才解决的,不多说,贴代码:
<ScrollView
android:id="@+id/sc_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:minHeight="360dp"
android:scrollbars="none">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:background="@null"
android:gravity="top|start"
android:hint="@string/FeedBackViewController_Placeholder"
android:lineSpacingMultiplier="1.0"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:maxHeight="450dp" //当初这个没加,也出现了滑动不了的情况
android:textSize="@dimen/font_size16"/>
</ScrollView>
代码里面需要:
editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// 解决scrollView中嵌套EditText导致不能上下滑动的问题
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
邮箱:8955556@qq.com
Q Q:8955556
这篇文章主要为大家详细介绍了Android自定义控件实现底部...
这篇文章主要介绍了Android中Toolbar随着Scro...
本文主要介绍了Java图表类库的相关知识。具有很好的参考价值...
本文主要介绍了GIt的基本操作。具有很好的参考价值,下面跟着...
共享内存是在两个正在运行的进程之间共享和传递数据的一种非常有...
这篇文章主要为大家详细介绍了Android自定义相机实现定时...
这篇文章主要介绍了CentOS6.5 上部署 MySQL5....
这篇文章主要介绍了Vue结合原生js实现自定义组件自动生成示...
最近在学习python网络编程这一块,在写简单的socket...
这篇文章主要介绍了微信小程序 数据交互与渲染实例详解的相关资...