2013-09-06 20 views
6

Moja główna aktywność ma wiele przycisków, które mieszczą się pod sobą na dużym ekranie tabletu, ale nie na mniejszym ekranie telefonu. Dodałem Scrollview, dzięki czemu użytkownik może przejść do innych przycisków, jeśli wielkość ekranu wymaga:ScrollView dodaje dużą przestrzeń na dole

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@drawable/bg" 
      android:gravity="center_horizontal"> 

    <TextView 
     android:id="@+id/trackSelectorText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal"/> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"     
      android:gravity="center_horizontal"> 

     <Button      
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="foo" /> 
     <!-- More buttons --> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

to trochę roboty, jednak mam dużą pustą przestrzeń poniżej na ostatni guzik (tj Scrollview puszka przewiń w dół za daleko). Zarówno na prawdziwym tablecie, jak i na emulatorze z konfiguracją telefonu. Jeśli I center wewnętrzny LinearLayout (zamiast center_horizontal), przestrzeń jest równomiernie rozłożona między górną i dolną, której nie chcę ani. Jak naprawić ten układ?

Mam nadzieję, że ten obraz będzie wyraźniejszy, wyobraź sobie, że ScrollView został przewinięty w dół i pokazuje ostatnie przyciski. Puste miejsce Znaczy to jeden poniżej przycisk 6 na prawym obrazie:

enter image description here

+0

można narysować to, co chcesz? – Shark

+0

Zrobione, mam nadzieję, że ułatwi to wizualizację. – Lennart

+0

spróbuj podać 'ScrollView'' android: layout_height = "match_parent" '. Wątpię, by przestrzeń była wewnątrz przewijania, ale faktycznie poniżej –

Odpowiedz

10

Właściwie, to nie było związane z układem (chyba, że ​​czegoś mi brakuje). Próbowałem skomentować przypisane tło i nagle zadziałało. Obraz w tle (@drawable/bg) był po prostu zbyt duży i spowodował przewijanie. Przekształciłem tło w 9-plasterkowy obraz, aby mógł być skalowany automatycznie, a voila, dodatkowe miejsce zniknęło. Nadal, gdyby to było możliwe bez 9-łaty, nadal chciałbym usłyszeć, czy można to zrobić w pliku XML.

1

Sprawdziłem z moim code..Work doskonale:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@drawable/bg" 
     android:gravity="center_horizontal"> 

<TextView 
    android:id="@+id/trackSelectorText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal"/> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"     
     android:gravity="center_horizontal"> 

    <Button      
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="foo" /> 
    <!-- More buttons --> 
    </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

Można pomóc. ...... !!

+0

A jaka jest różnica z oryginalnym kodem? –

8

Spróbuj dodać ten atrybut do swojego elementu ScrollView. android: fillViewport = "true"

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:fillViewport="true" > ... </ScrollVIew> 

Ref: ScrollView Ref

+1

android: layout_height = "match_parent" należy zmienić na android: layout_height = "0dp" – Mieszko

1

można użyć tego atrybutu w Scrollview uniknąć zaokrąglona na dole widzenia

android:overScrollMode="never" 
Powiązane problemy