2012-08-26 15 views
6

Robię aplikację dla urządzenia z Androidem i próbuję mieć ScrollView wewnątrz LinearLayout, ale kiedy próbuję to zrobić, ScrollView zabiera całą przestrzeń i elementy, które są po ScrollView w LinearLayout zniknie.Android: ScrollView w pionie LinearLayout

Na przykład:
Jeżeli Scrollview nie jest "pełny":
http://kakko76.free.fr/scroll2.jpg
Jeśli Scrollview jest "pełny":
http://kakko76.free.fr/scroll1.png

Jak widać przycisk disapear ...
Oto kod tego działania:

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

Po dodaniu elementów w Linea rLayout, którzy są w ScrollView.
Jakieś rozwiązanie?
Dzięki.

Odpowiedz

9

Spróbuj wykonać następujące czynności:

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

Mówi swoją Scrollview wziąć całą pozostałą przestrzeń zajmowaną przez nie innych elementów.

+1

Pisałem to samo rozwiązanie w tym samym czasie :-p byłeś szybszy .. –

+0

Dziękuję to praca :) – kakko76

1

Masz android:layout_height="wrap_content" jako swój wzrost. oznacza to, że wysokość jest tak wysoka, jak zawartość w niej zawarta. jeśli nie chcesz, aby zajęło całe miejsce, możesz nadać mu wagę (jak na powyższej odpowiedzi) lub możesz ustawić swoją wysokość za pomocą dp. na przykład:

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

jak widać dałem układ liniowy jest „suma” i wszystkie jego dzieci są podane wagi. jest jasne? czy to jest to, czego potrzebujesz?

Powiązane problemy