国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

詳解Android ScrollView嵌套EditText出現的滑動問題

2019-10-22 18:17:38
字體:
來源:轉載
供稿:網友

今天項目中需求是寫出一個很簡單的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;          }      });

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鄂伦春自治旗| 桐城市| 桃园市| 黄大仙区| 色达县| 东乡县| 灌南县| 门头沟区| 体育| 阜城县| 海伦市| 大连市| 新丰县| 邵阳市| 宣城市| 宁安市| 榆树市| 敦煌市| 永兴县| 呼伦贝尔市| 郸城县| 竹山县| 黄平县| 方正县| 长宁县| 克山县| 北宁市| 龙泉市| 郯城县| 麦盖提县| 京山县| 扬中市| 深圳市| 贡嘎县| 哈密市| 新竹市| 东乌珠穆沁旗| 班玛县| 嵊泗县| 台中县| 托克托县|