欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Android ScrollView嵌套EditText出現(xiàn)的滑動問題

 更新時間:2018年01月04日 09:15:25   作者:黑石ZB  
本篇文章主要介紹了詳解ScrollView嵌套EditText出現(xiàn)的滑動問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

今天項目中需求是寫出一個很簡單的edittext輸入框,但要求當輸入字數(shù)過長時需要上下滑動以便查看所有文字,因為頁面底部有一個"確定"的button,但剛開始輸入框內(nèi)的問題怎么都滑動不了,我一開始就想到了這是事件傳遞沖突問題,但試了很多種方法都不行,最后也是一個一個試才解決的,不多說,貼代碼:

<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" //當初這個沒加,也出現(xiàn)了滑動不了的情況
      android:textSize="@dimen/font_size16"/>
  </ScrollView>

代碼里面需要:

editText.setOnTouchListener(new View.OnTouchListener() {
        @Override
          public boolean onTouch(View v, MotionEvent event) {
           // 解決scrollView中嵌套EditText導(dǎo)致不能上下滑動的問題
             v.getParent().requestDisallowInterceptTouchEvent(true);
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_UP:
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
           }
           return false;
          }
      });

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論