2013-02-11 25 views
15

Ich kann ScrollView nicht ordnungsgemäß scrollen. Es schnitt immer den Inhalt auf der Unterseite ab, als ob es ein normales LinearLayout wäre.ScrollView scrollt überhaupt nicht

Mein Code

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" > 

    <LinearLayout android:id="@+id/scroll_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:isScrollContainer="true" 
     android:orientation="vertical" > 

Natürlich habe ich versucht, die „fillViewport“ und „isScrollContainer“ Eigenschaften bereits hinzufügen/entfernen, und es überhaupt nichts ändern.

Vielen Dank im Voraus.

+0

können Sie bitte die kompletten XML einfügen, vielleicht ist etwas mit Ihrem Linearlayout verwendet. – PaNaVTEC

+0

Versuchen Sie, 'android: layout_height =" match_parent "' auf 'android: layout_height =" 0dp "' zu ändern und fügen Sie 'android: layout_weight =" 1 "' auf der 'ScrollView' hinzu. –

+0

Nur versucht und kein Glück. – thomaus

Antwort

19

Antwort: Die ScrollView funktioniert nicht, wenn sie als Wurzelelement eines XML-Layouts verwendet wird. Es muss in ein LinearLayout eingepackt werden.

Lösung dann:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ScrollView android:id="@+id/scroll_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true" > 

     <LinearLayout android:id="@+id/scroll_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 
+47

das funktioniert nicht für mich ... – Ciprian

+0

Sind Sie sicher? !! –

+1

+1 Hat tatsächlich für mich gearbeitet, danke. –

2

entfernen Sie die android:isScrollContainer in LinearLayout. Gemäß der Dokumentation wird android:isScrollContainer verwendet, um die Ansicht scrollbar zu setzen. Ich hoffe es hilft dir. Siehe hierzu link zur Definition.

2

Android Studio fügt eine NestedScrollView auf die Aktivitätsdatei einiger seiner Vorlagen (zum Beispiel Master-Detail). Wenn Sie eine ScrollView in der Fragmentdatei und eine weitere in der Aktivitätsdatei dieses Fragments verwenden, wird verhindert, dass die Bildlaufansicht funktioniert. Das Entfernen der ScrollView in meiner Fragmentdatei und das Hinterlassen der Datei in der Aktivitätsdatei hat das Problem für mich gelöst.

0

Probieren Sie diese Lösung aus, verzögern Sie Ihren Scroll nur mit der post-verzögerten Methode.

fragment_test.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rootRelativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:fresco="http://schemas.android.com/apk/res-auto"> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="40dp" 
     android:fillViewport="true" 
     android:scrollbars="none"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      ... 
     </RelativeLayout> 

    </ScrollView> 

</RelativeLayout> 

TestFragment.java

... 
private ScrollView mScrollView; 
... 
mScrollView = (ScrollView) mView.findViewById(R.id.scrollView); 
mScrollView.setSmoothScrollingEnabled(true); 
... 
new Handler().postDelayed(new Runnable() { 
    @Override 
    public void run() { 
     if(isAdded()) { 
      // Scroll 1000px down 
      mScrollView.smoothScrollTo(0, 1000); 
     } 
    } 
}, 150); 

Das ist für mich gearbeitet, hoffe, das hilft.

0

Diese feste mein Problem: Ich android:isScrollContainer="true" zu einem Linearlayout hinzugefügt und entfernt die Scroll Code vor:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<ScrollView 
    android:id="@+id/scrollViewRecords" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:id="@+id/sheepList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    </LinearLayout> 
</ScrollView> 
</LinearLayout> 

-Code Nach

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:isScrollContainer="true"> 

    <LinearLayout 
     android:id="@+id/sheepList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    </LinearLayout> 
</LinearLayout> 
0

Gibt es eine Möglichkeit, dies zu schließen Frage? es ist alt und aktuell hat die als gültig markierte Antwort keinen Sinn. Die einzige gültige Sache in Bezug auf ScrollView im Moment ist diese:

Eine Ansichtsgruppe, die ermöglicht, dass die darin platzierte Ansichtshierarchie gescrollt wird. In der Bildlaufansicht darf nur ein direktes untergeordnetes Element angezeigt werden. Um mehrere Ansichten innerhalb der Bildlaufansicht hinzuzufügen, erstellen Sie das direkte untergeordnete Objekt, dem Sie eine Ansichtsgruppe hinzugefügt haben, z. B. LinearLayout, und platzieren Sie weitere Ansichten in diesem LinearLayout. Fügen Sie RecrollerView oder ListView niemals einer Bildlaufansicht hinzu. Dies führt zu einer schlechten Benutzeroberflächenleistung und einer schlechten Benutzererfahrung.

aus offizieller Dokumentation Genommen: https://developer.android.com/reference/android/widget/ScrollView.html

0

Die gewählte Antwort ist nicht korrekt!

Sie können ScrollView als Root-Ansicht verwenden, es funktioniert nicht für Sie, weil Sie die Auffüllung fehlen.

hinzufügen so etwas wie:

android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
Verwandte Themen