2013-06-19 2 views
6

Ich habe versucht, eine Bildlaufansicht um alles auf einem Aktivitätslayout hinzuzufügen, aber es gab mir eine Fehlermeldung, dass es nur um eine Sache herum platziert werden kann.Wie fügt man eine Scroll-Ansicht zu einer gesamten Aktivität hinzu?

Meine Aktivität, hat einen Titel Textview dann ein Bild, dann eine Beschreibung Textansicht, und Sie können nicht die ganze Beschreibung lesen, weil es zu lang ist und unter dem Rand meines Bildschirms geht. Wie kann ich die Whoel-Sache scrollbar machen?

Meine xml sieht wie folgt aus:

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

nur Ihre Eltern Linearlayout innerhalb Scroll-Ansicht \ – abhi

Antwort

27

Try this:

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

Die "eins" Ihre LinearLayout ist. Wickeln Sie das einfach in eine ScrollView und Sie werden das Layout für die gesamte Aktivität kapseln.

Außerdem, wenn Sie nur ein elemtnet in einem ScrollView alles, was Sie tun müssen, wickeln will, ist in einem eigenen Layout, das Element setzen, wie eine lineare oder relative Layout, und dann wird das das ein Element Ihrer ScrollView

1

Wickeln Sie die LinearLayout (Höhe ist wrap_content) mit SrollView (Höhe ist fill_parent).

0

nur verwenden diese

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

bei der linearen Layout Linie füge ich diese Störung erhalte: Mehrere Anmerkungen gefunden bei Diese Zeile: \t - Der Elementtyp "ScrollView" muss von den Attributspezifikationen ">" \t oder "/>" gefolgt werden. \t - Fehler: Fehler bei der Analyse XML: nicht wohlgeformt (ungültige Token) – Mike

+1

Es fehlt die>, müssen Sie es auch das Ende sollte nicht sein. Schließlich, mit scrollviews, möchten Sie vielleicht das Attribut android hinzufügen: fill_viewport = "true", so dass Ihre scrollview den gesamten Bildschirm abdeckt. – ootinii

+0

ja, das war zur bearbeiteten Zeit verfehlt, aber es sollte jetzt gut funktionieren :) – abhi

Verwandte Themen