2017-09-15 4 views
0

Ich möchte eine "fixed_space" am oberen Rand des Bildschirms und eine "scrollview" am unteren Rand des Bildschirms, die unterhalb von fixed_space sein sollte. Der Rest des Bildschirms ist ein Container "rest_space".Android Scrollview Content-Größe kleiner als sollte

Leider hat meine scrollview eine kürzere Höhe (um 100dp was fixed_space hat), wenn der Inhalt zu groß/scrollbar ist.

Ich versuchte, das gleiche mit ConstraintLayout und RelativeLayout zu erreichen, aber ich habe das gleiche Ergebnis. Irgendwelche Ideen warum scrollview hat 100dp kürzere Höhe, wie es sein sollte?

EDIT: Scrollview sollte so viel Platz nehmen, wie sie benötigt.

<?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"> 

    <View 
     android:id="@+id/fixed_space" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:background="@android:color/holo_red_dark" /> 

    <View 
     android:id="@+id/rest_space" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/black" /> 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/holo_green_dark" 
     android:fillViewport="true"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" /> 

    </ScrollView> 
</LinearLayout> 
+0

Haben Sie versucht, die "rest_space" Ansicht zu entfernen, dass das Problem Sag mir Verhältnis sein sollte –

+0

von fixed_space, rest_space und Scroll Sie wollen?. –

+0

@PierGiorgioMisley ScrollView sollte nur so viel Platz einnehmen, wie sie benötigt. Wenn ich rest_space lösche, nimmt scrollview den gesamten Abstand zwischen fixed_space und bottom screen. – prosto

Antwort

0

Try this:

<?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"> 

<View 
    android:id="@+id/fixed_space" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:background="@android:color/holo_red_dark" /> 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <View 
     android:id="@+id/rest_space" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/scrollview" 
     android:background="@android:color/black" /> 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/holo_green_dark" 
     android:fillViewport="true"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" /> 

    </ScrollView> 


</RelativeLayout> 


</LinearLayout> 
+0

Wenn ich Text auf Android: Text = "Start von ScrollView" wo ist kein Rest_space und Scrollview ist nicht am unteren Rand des Bildschirms, wie sie sein sollte. – prosto

+0

Ich habe eine Bearbeitung vorgenommen. Bitte versuchen Sie es. –

+0

Es funktioniert! Fügen Sie am Ende ein schließendes Tag für LinearLayout hinzu. – prosto

0

Ok, ich denke, das Ihr probem lösen sollte:

Zuerst begann ich von RelativeLayout verwenden. Ich habe es getan, um den fixed_space nach oben und den scrollview nach unten auszurichten.

Dann änderte ich die Ansicht für eine Linearlayout und Textview in ihn setzen, so konnte ich wrap_content und das ist der schwierige Teil verwenden:

Wenn Sie Scroll mit wrap_content und einer Ansicht mit dem Gewicht Material verwenden, kann Android Mache keine Berechnungen, damit der Bildschirm angezeigt wird, weil keine Referenz vorhanden ist. Wenn ich die TextView mit wrap_content selbst lege, gibt das die Referenz, weil Android die Größe des Textes kennt.

Sie müssen nicht die TextView verwenden, aber Sie brauchen alles, das Android diese Referenz gibt.

In diesem Fall wird die Scrollansicht gestreckt, nicht die LinearLayout. Wenn du möchtest, dass die zweite sich anpasst, dann musst du deiner Scrollview eine feste Höhe zuweisen.

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

<View 
    android:id="@+id/fixed_space" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_alignParentTop="true" 
    android:background="@android:color/holo_red_dark" /> 

<LinearLayout 
    android:id="@+id/rest_space" 
    android:layout_below="@+id/fixed_space" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/black"> 

    <TextView 
     android:text="Test" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

<ScrollView 
    android:id="@+id/scrollview" 
    android:layout_below="@id/rest_space" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_green_dark" 
    android:layout_alignParentBottom="true"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" /> 

</ScrollView> 
</RelativeLayout> 
+0

Vielen Dank für Ihre Antwort. Aber ich habe meine Frage wahrscheinlich schlecht beschrieben. ScrollView sollte eine dynamische Höhe haben. Wenn TextView in der Bildlaufansicht nur "Start der Bildlaufansicht" hat, ist die Höhe der Bildlaufleiste nur eine Zeilenhöhe und bleibt am unteren Bildschirmrand. "rest_space" height nimmt den verbleibenden Abstand zwischen "fixed_space" und "scrollview" ein. – prosto