2014-06-26 5 views
21

Ich habe eine Scrollview innerhalb der es eine Editext ist, die multiline ist. Ich möchte den Editiertext scrollen, um den niedrigeren Inhalt zu sehen, aber es kann nicht gemacht werden.Wie scrolle ich den Edittext innerhalb der Scrollview

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:background="@android:color/holo_blue_light" 
     android:gravity="center" > 
     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="View Complaint" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 
    </LinearLayout> 
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:padding="20dp" > 
      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dp" 
       android:text="Order Number 0100C1" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:text="Name of ClientClient 1" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 
       android:id="@+id/textView4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:text="Subject : Measurement Issues" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 
       android:id="@+id/textView5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="25dp" 
       android:text="Description" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <TextView 
       android:id="@+id/textView6" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dp" 
       android:text="Lorem ipsum dolor sit amet, sapien etiam, nunc amet dolor ac odio mauris justo. Luctus arcu, urna praesent at id quisque ac. Arcu massa vestibulum malesuada, integer vivamus el/ eu " 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 
       <TextView 
        android:id="@+id/textView7" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="2dp" 
        android:text="Assign to" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
       <Spinner 
        android:id="@+id/spinner1" 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:entries="@array/array_name" /> 
      </LinearLayout> 
      <EditText 
       android:id="@+id/editText1" 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:layout_marginTop="15dp" 
       android:background="#eeeeee" 
       android:inputType="textMultiLine" 
       android:singleLine="false" 
       android:text="Android applications normally run entirely on a single thread by    default the “UI thread” or the “main thread”. 

      android:textAppearance="?android:attr/textAppearanceMedium" ></EditText> 
      <TextView 
       android:id="@+id/textView5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:text="Comment History" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="fill_parent" 
       android:layout_height="147dp" 
       android:src="@drawable/adddd" /> 
      <CheckBox 
       android:id="@+id/checkBox1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:text="Close Complaints" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 
      <Button 
       android:id="@+id/login" 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="match_parent" 
       android:layout_height="45dp" 
       android:layout_below="@+id/ll" 
       android:layout_marginLeft="20dp" 
       android:layout_marginRight="20dp" 
       android:layout_marginTop="15dp" 
       android:background="@drawable/login_btn" 
       android:text="Submit" 
       android:textColor="@android:color/holo_blue_dark" 
       android:textSize="25dp" 
       android:textStyle="bold" /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

enter image description here

Könnt ihr mir dabei helfen. Ich denke, editText bekommt den Fokus, wenn der Cursor darin ist.

Danke .. !!!!!

+1

Dies ist ein strukturelles Problem mit mit einem Scroll-EditText innerhalb einer ScrollView. Da Sie die ScrollView haben, lassen Sie EditText nur nach Bedarf wachsen. Es ist keine EditText-Bildlaufleiste erforderlich. Das erinnert mich an frustrierende Webseiten mit einem scrollenden iFrame, der größer ist als das Browserfenster. Ich hoffe, Sie haben eine Lösung gefunden, die für Sie arbeitet. –

Antwort

22

die Sie interessieren ..

unten Linien Fügen Sie in Ihrem EditText

android:overScrollMode="always" 
android:scrollbarStyle="insideInset" 
android:scrollbars="vertical" 

Beispiel

<EditText 
     android:id="@+id/editText1" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:layout_marginTop="15dp" 
     android:background="#eeeeee" 
     android:inputType="textMultiLine" 
     android:singleLine="false" 
     android:overScrollMode="always" 
     android:scrollbarStyle="insideInset" 
     android:scrollbars="vertical" 
     android:text="Android applications normally run entirely on a single thread by    default the “UI thread” or the “main thread”. 
     android:textAppearance="?android:attr/textAppearanceMedium" > 
    </EditText> 

EDIT

programmatische

ly
youredittext.setOnTouchListener(new OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 

      v.getParent().requestDisallowInterceptTouchEvent(true); 
      switch (event.getAction() & MotionEvent.ACTION_MASK){ 
      case MotionEvent.ACTION_UP: 
        v.getParent().requestDisallowInterceptTouchEvent(false); 
        return true; 
      } 
      return false; 
     } 
}); 
+0

Lassen Sie mich das versuchen .... Danke – Gattsu

+3

Noch ist es nicht funktioniert :( – Gattsu

+0

@Manish Siehe meine Bearbeitung Programmatisch versuchen, dass. – Hariharan

41

Zuerst dies bei XML hinzufügen

android:scrollbarStyle="insideInset" 
android:scrollbars="vertical" 
android:overScrollMode="always" 

Dann die gleiche oben "OnTouch" hinzufügen, aber es "false" nicht "true"

public boolean onTouch(View view, MotionEvent event) { 

        if (view.getId() == R.id.DwEdit) { 
         view.getParent().requestDisallowInterceptTouchEvent(true); 
         switch (event.getAction()&MotionEvent.ACTION_MASK){ 
         case MotionEvent.ACTION_UP: 
          view.getParent().requestDisallowInterceptTouchEvent(false); 
          break; 
         } 
        } 
        return false; 
} 
+4

Wenn Sie während der Eingabe von der Tastatur aus drücken Es ist Scrolling Parent Scrollview –

+1

Die richtige Antwort. –

+0

Es ist korrekt, es ist hilfreich für mich –

1

machen zurückkehren würde ich wählen Sie oben die aktualisierte Antwort von @Ayman Mahgoub zur Verfügung gestellt, aber ich weiß nicht hoch genug Ruf. Sein Code funktioniert. Ich musste die Rückgabe ändern, um false zurückzugeben. Sie setzen die .setOnTouchListener() -Methode in Ihrer Java-Klasse und setzen die drei Linien:

android:scrollbarStyle="insideInset" 
android:scrollbars="vertical" 
android:overScrollMode="always" 

in der entsprechenden XML-Datei. Sie können die Implementierung im Android Emulator sehen, und auf dem Android-Handy verwenden Sie zum Testen. Vielen Dank @Ayman Mahgoub und @Hariharan!

3

Aufbauend auf die Antwort von @Ayman Mahgoub und @Hariharan. Die Lösung funktionierte großartig, außer beim Scrollen des Bearbeitungstextes gibt es kein Scroll-Momentum. Sobald sich der Finger hebt, stoppt das Scrollen sofort.

Um Scrollimpuls zu erhalten, wickeln Sie einen Scrollview um den EditText herum und lassen Sie den Inhalt des EditText height umbrechen (setzen Sie minHeight, wenn Sie möchten). Entfernen Sie die folgenden Zeilen aus dem Text bearbeiten:

android:scrollbarStyle="insideInset" 
android:scrollbars="vertical" 
android:overScrollMode="always" 

Nun ist die verschachtelte Scroll um die EditText gewickelte Pflege des Scrollens nimmt. Aktualisieren Sie die OnTouch Handler zu berücksichtigen, die aktualisierte Ansicht Hierarchie:

public boolean onTouch(View view, MotionEvent event) { 
    v.getParent().getParent().requestDisallowInterceptTouchEvent(true); 
    switch (event.getAction() & MotionEvent.ACTION_MASK){ 
     case MotionEvent.ACTION_UP: 
      v.getParent().getParent().requestDisallowInterceptTouchEvent(false); 
      break; 
    } 
    return false; 

gewarnt wird diese Lösung nun eng gekoppelt an die Ansichtshierarchie.

Gist: https://gist.github.com/atoennis/7549fba2634d0abccddf

+0

Meine Antwort oben ist datiert. @ HungNM2 hat die modernere und korrekte Antwort. – Adam

+0

Ich habe eine "ScrollView", die mehrere Ansichten enthält, und nur eine davon ist ein 'EditText'. Nimmt diese Lösung nur einen 'EditText' in der' ScrollView' an? Oder fügen Sie eine zusätzliche 'ScrollView' hinzu, nur um' 'EditText'' zu umbrechen? –

+0

Es hat für mich funktioniert! Vielen Dank! –

3

sollten Sie NestedScrollView Klasse. Diese Klasse unterstützt das Scrollen innerhalb des übergeordneten Scrollings.Diese Klasse kann ein Kind oder ein Elternteil sein.

<android.support.v4.widget.NestedScrollView   
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#d6d8d9"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxLines="512" 
       android:text=" your content"/> 
     <android.support.v4.widget.NestedScrollView 
      android:layout_below="@id/ll_button" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:background="#d6d8d9"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="your content" 
       android:maxLines="512"/>  
     </android.support.v4.widget.NestedScrollView>  
    </LinearLayout> 

</android.support.v4.widget.NestedScrollView>   
1

Verwenden Sie diesen Code Seine Arbeits

in Xml

android:singleLine="false" 
android:overScrollMode="always" 
android:scrollbarStyle="insideInset" 
android:scrollbars="vertical" 

in Pragraming

et_feedback.setOnTouchListener(new View.OnTouchListener() { 

      public boolean onTouch(View view, MotionEvent event) { 

       if (view.getId() == R.id.et_feedback) { 
        view.getParent().requestDisallowInterceptTouchEvent(true); 
        switch (event.getAction() & MotionEvent.ACTION_MASK) { 
         case MotionEvent.ACTION_UP: 
          view.getParent().requestDisallowInterceptTouchEvent(false); 
          break; 
        } 
       } 
       return false; 
      } 
     }); 
0

Dieses wi ll die EditText blättern und bearbeitbar machen:

Zuerst in der XML-Datei, fügen Sie diese:

android:overScrollMode="always" 
android:scrollbarStyle="insideInset" 
android:scrollbars="vertical" 

Dann in der Java-Datei, fügen Sie diese:

EditText.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View view, MotionEvent motionEvent) { 
      view.getParent().requestDisallowInterceptTouchEvent(true); 
      switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) { 
       case MotionEvent.ACTION_SCROLL: 
        view.getParent().requestDisallowInterceptTouchEvent(false); 
        return true; 
       case MotionEvent.ACTION_BUTTON_PRESS: 
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.showSoftInput(EditText, InputMethodManager.SHOW_IMPLICIT); 
      } 
      return false; 
     } 
}); 
Verwandte Themen