2012-04-18 3 views
97

Ich habe eine RelativeLayout in einem ScrollView. Meine RelativeLayout hat android:layout_height="match_parent" aber die Ansicht nimmt nicht die gesamte Größe, es ist wie ein wrap_content.Innerhalb von ScrollView anzeigen nicht alle Platz

Gibt es eine Möglichkeit, das echte Verhalten fill_parent/match_parent zu haben?

Mein Layout:

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

    <ImageView 
    android:id="@+id/top" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:scaleType="fitXY" 
    android:src="@drawable/top" /> 

    <ImageView 
    android:id="@+id/header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/top" 
    android:scaleType="fitXY" 
    android:src="@drawable/headerbig" /> 

    <ImageView 
    android:id="@+id/logo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/header" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="3dp" 
    android:src="@drawable/logo" /> 

    <ScrollView 
    android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottom" 
    android:layout_below="@+id/logo" 
    android:background="@drawable/background" > 

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

      <ImageView 
      android:id="@+id/dashboard01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/dashboard02" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="30dp" 
      android:src="@drawable/dashboard01" 
      android:visibility="visible" /> 

      <ImageView 
      android:id="@+id/dashboard02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="10dp" 
      android:src="@drawable/dashboard02" /> 

      <ImageView 
      android:id="@+id/dashboard03" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/dashboard02" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="40dp" 
      android:src="@drawable/dashboard03" 
      android:visibility="visible" /> 
     </RelativeLayout> 
    </ScrollView> 

    <ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/logo" 
    android:layout_centerHorizontal="true" 
    android:scaleType="fitXY" 
    android:src="@drawable/bar" /> 

    <ImageView 
    android:id="@+id/bottom" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:scaleType="fitXY" 
    android:src="@drawable/bottom" /> 

</RelativeLayout> 

Antwort

324

Versuchen Hinzufügen android:fillViewport="true" zu Ihrem Scroll

daran erinnern, dass android:layout_height=”fill_parent” bedeutet Dies ist natürlich nicht das, was Sie wollen, wenn „die Höhe der Mutter auf die Höhe festgelegt.“ mit einem ScrollView. Schließlich würde die ScrollView nutzlos werden, wenn ihr Inhalt immer so groß wäre wie sie selbst. Um dies zu umgehen, müssen Sie das ScrollView-Attribut android:fillViewport verwenden. Wenn dieses Attribut auf "True" festgelegt ist, wird das untergeordnete Element der Bildlaufansicht bei Bedarf auf die Höhe von ScrollView erweitert. Wenn das Kind größer als ScrollView ist, hat das Attribut keine Auswirkungen.

http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/

+0

Es funktioniert perfekt. Warum? – Corbella

+1

Das Gleiche gilt für HorizontalScrollView. – CoolMind

+0

Dies funktioniert auch für NestedScrollView (23.4), danke! –

1

Nur android hinzufügen: fillViewport = "true" in yout xml Layout in Scroll

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

<!--define views here--> 


</ScrollView>