2013-06-19 15 views
6

Próbowałem dodać widok przewijania wokół wszystkiego w układzie działania, ale dało mi to błąd, mówiąc, że można go umieścić tylko wokół jednej rzeczy.Jak dodać widok przewijania do całej aktywności?

Moja aktywność, ma tytułowy widok tekstowy, a następnie obraz, a następnie opisowy opis tekstu, a nie można przeczytać całego opisu, ponieważ jest długi i znajduje się poniżej krawędzi ekranu. Jak mogę przewinąć rzeczy whoela?

Moje XML wygląda następująco:

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


    <TextView 
     android:id="@+id/beerTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="40sp" 
     android:textStyle = "bold" 
     > 
    </TextView> 

    <ImageView android:id="@+id/image" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_margin="10dip"/> 

    <Button 
     android:id="@+id/buttonBrewery" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="" /> 
    <Button 
     android:id="@+id/buttonStyle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="" /> 

    <TextView 
     android:id="@+id/beerDEscriptionTitle" 
     android:textStyle = "bold" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="20sp" 
     android:text="Description" 
     ></TextView> 
    <TextView 
     android:id="@+id/beerDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="15sp" 

     ></TextView> 

</LinearLayout> 
+0

wystarczy dodać linearlayout nadrzędnej wewnątrz widoku przewijania \ – abhi

Odpowiedz

27

Spróbuj tego:

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

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

     <!-- TextView and other stuff --> 

    </LinearLayout> 
</ScrollView> 
0

W "jedno" to LinearLayout. Po prostu zapakuj to w ScrollView i obuduj układ dla całej aktywności.

Dodatkowo, jeśli chcesz, aby owinąć tylko jeden elemtnet w ScrollView wszystko co musisz zrobić, to umieścić ten element w jego własnym układzie, jak liniowy lub układzie względnym, a następnie, że staje się jeden element Twojego ScrollView

1

Zawiń LinearLayout (wysokość to wrap_content) z SrollView (wysokość to fill_parent).

0

prostu użyć tego

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/scrollview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


    <TextView 
     android:id="@+id/beerTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="40sp" 
     android:textStyle = "bold" 
     > 
    </TextView> 

    <ImageView android:id="@+id/image" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_margin="10dip"/> 

    <Button 
     android:id="@+id/buttonBrewery" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="" /> 
    <Button 
     android:id="@+id/buttonStyle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="" /> 

    <TextView 
     android:id="@+id/beerDEscriptionTitle" 
     android:textStyle = "bold" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="20sp" 
     android:text="Description" 
     ></TextView> 
    <TextView 
     android:id="@+id/beerDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="15sp" 

     ></TextView> 

</LinearLayout> 
</ScrollView> 
+0

na liniowej układu Dostaję taki błąd: Wiele adnotacje znaleźć na linia ta: \t - Po typie elementu "ScrollView" muszą następować specyfikacje atrybutów, ">" \t lub "/>". \t - error: Błąd parsowania XML: źle sformułowany (nieprawidłowy token) – Mike

+1

Brakuje>, musisz zrobić to , również koniec powinien być nie . Wreszcie, z przewijanymi widokami, możesz chcieć dodać atrybut android: fill_viewport = "true", aby twój scrollview obejmował cały ekran. – ootinii

+0

Tak, brakowało tego w edytowanym czasie, ale teraz powinno działać dobrze :) – abhi

Powiązane problemy