9

Tôi đã tìm kiếm tất cả các bài viết liên quan đến chủ đề này, nhưng tôi vẫn không thể tìm thấy bất kỳ giải pháp. Tôi có một bố cục lớn và có thể cuộn được bằng ScrollView và nó cũng có EditText có thể cuộn được. Nếu tôi cố gắng di chuyển văn bản, bố cục đang bắt đầu cuộn. Làm thế nào tôi có thể giải quyết nó?cuộn EditText bên scrollview

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ScrollView 
     android:id="@+id/lroot" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 

     > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 

      <ImageView 
       android:id="@+id/img6" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:gravity="right" 
       android:onClick="runInfo" 
       android:src="@drawable/info_btn" /> 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/splash" /> 

      <!-- Scrollable EditText --> 
      <EditText 
       android:id="@+id/EditText01" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:autoLink="all" 
       android:background="@drawable/isim_soyisim" 
       android:clickable="true" 
       android:cursorVisible="true" 
       android:gravity="left|top" 
       android:scrollbars="vertical" 
       android:inputType="textMultiLine" 
       android:longClickable="false" 
       android:maxLines="5" 
       android:singleLine="false" 

      /> 


     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 
+0

theo xml, bố cục của bạn có nghĩa vụ phải được cuộn .... – waqaslam

+0

như vậy, những gì shoud tôi làm gì? –

+0

đóng gói EditText của bạn với trong scrollview ... – waqaslam

Trả lời

7

Hãy thử giải pháp này

Ref link

EditText EtOne = (EditText) findViewById(R.id.EditText01); 
    EtOne.setOnTouchListener(new OnTouchListener() { 
       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
        if (v.getId() == R.id.comment1) { 
         v.getParent().requestDisallowInterceptTouchEvent(true); 
         switch (event.getAction() & MotionEvent.ACTION_MASK) { 
         case MotionEvent.ACTION_UP: 
          v.getParent().requestDisallowInterceptTouchEvent(false); 
          break; 
         } 
        } 
        return false; 
       } 
      }); 
0
package com.sam.views; 

import android.content.Context; 
import android.util.AttributeSet; 
import android.util.Log; 
import android.view.MotionEvent; 
import android.widget.ScrollView; 

public class CustomScrollview extends ScrollView{ 

    public CustomScrollview(Context context) { 
     super(context); 
    } 

    public CustomScrollview(Context context, AttributeSet attrs) { 
      super(context, attrs); 
     } 

     public CustomScrollview(Context context, AttributeSet attrs, int defStyle) { 
      super(context, attrs, defStyle); 
     } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) { 
     final int action = ev.getAction(); 
     switch (action) 
     { 
      case MotionEvent.ACTION_DOWN: 
        super.onTouchEvent(ev); 
        break; 

      case MotionEvent.ACTION_MOVE: 
        return false; // redirect MotionEvents to ourself 

      case MotionEvent.ACTION_CANCEL: 
        super.onTouchEvent(ev); 
        break; 

      case MotionEvent.ACTION_UP: 
        return false; 

      default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action); break; 
     } 

     return false; 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     super.onTouchEvent(ev); 
     return true; 
    } 
}