2012-08-26 19 views
6

Ich mache eine App für Android-Gerät und ich versuche, eine ScrollView in einem LinearLayout zu haben, aber wenn ich dies versuche, nehmen die ScrollView den ganzen Raum und Elemente, die nach der ScrollView sind im LinearLayout verschwinden.Android: ScrollView im vertikalen LinearLayout

Zum Beispiel:
Wenn die Scrollview ist nicht "voll":
http://kakko76.free.fr/scroll2.jpg
Wenn die Scrollview "voll" ist:
http://kakko76.free.fr/scroll1.png

Wie Sie auf den Button disapear sehen ...
Hier ist der Code dieser Aktivität:

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_marginLeft="50dp" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:orientation="vertical" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:background="@drawable/linearlayoutbackground" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/nom_des_joueurs" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_marginBottom="30dp" /> 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

     </LinearLayout> 

    </ScrollView> 

    <Button 
     android:id="@+id/okPlayersName" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/ok" 
     android:background="@drawable/backgroundbutton" 
     android:layout_marginTop="30dp" /> 
</LinearLayout> 

Nachdem ich Elemente in der Linea hinzufügen rLayout, die in der ScrollView sind.
Irgendeine Lösung?
Danke.

Antwort

9

Versuchen Sie Folgendes:

android:layout_height="0dp" 
android:layout_weight="1" 

dies Ihre Scroll erzählt von den anderen Elementen all den verbleibenden Platz nicht besetzt zu nehmen.

+1

Schreib die gleiche Lösung zur gleichen Zeit: -p warst du schneller .. –

+0

Vielen Dank, es ist Arbeit :) – kakko76

1

Sie hatten android:layout_height="wrap_content" als Ihre Höhe. das bedeutet, dass die Höhe so hoch ist wie der Inhalt darin. Wenn du nicht willst, dass es den ganzen Platz einnimmt, kannst du ihm Gewicht geben (wie die obige Antwort) oder du kannst deine Höhe mit dp einstellen. zum Beispiel:

<LinearLayout 
android:id="@+id/linearLayout1" 
android:layout_width="fill_parent" 
android:layout_marginLeft="50dp" 
android:layout_height="wrap_content" 
android:layout_centerHorizontal="true" 
android:layout_centerVertical="true" 
android:orientation="vertical" 
android:focusable="true" 
android:focusableInTouchMode="true" 
android:background="@drawable/linearlayoutbackground" 
android:weightSum="1.5" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight = "0.2" 
    android:text="@string/nom_des_joueurs" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_marginBottom="30dp" /> 

<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight = "1"> 

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

    </LinearLayout> 

</ScrollView> 

<Button 
    android:id="@+id/okPlayersName" 
    android:layout_width="match_parent" 
    android:layout_height="0" 
    android:layout_weight = "0.3"> 
    android:text="@string/ok" 
    android:background="@drawable/backgroundbutton" 
    android:layout_marginTop="30dp" /> 

wie man sehen kann ich gab das lineare Layout eine „Summe“ und alle seine Kinder gegeben Gewicht. ist es klar? Ist es das, was du brauchst?