2013-06-19 101 views
6

我試着在活動版面上添加一個滾動視圖,但它給了我一個錯誤,說它只能放在一件事情上。如何將滾動視圖添加到整個活動?

我的活動,有一個標題textview然後是圖像,然後是描述文本視圖,並且您不能閱讀整個描述,因爲它的長度並且低於我的屏幕邊緣。我怎樣才能使滾動的滾動?

我的XML看起來是這樣的:

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

只是在線性輪廓線,我得到這個錯誤添加你的父母的LinearLayout滾動視圖裏面\ – abhi

回答

27

試試這個:發現在 多個批註:

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

的 「一件事」 是你LinearLayout。只需將其包裝在ScrollView中,即可封裝整個活動的佈局。

此外,如果你想換一個ScrollView只是一個elemtnet所有您需要做的就是把該元素在它自己的佈局,像線性或相對佈局,那麼它將成爲你的ScrollView

的一個元素
1

LinearLayout(高度爲wrap_content)與SrollView(高度爲fill_parent)包裝在一起。

0

只是用這個

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

此行: \t - 元素類型「ScrollView」必須後跟任一屬性規格,「>」 \t或「/>」。 \t - 錯誤:解析XML時出錯:格式不正確(無效標記) – Mike

+1

它缺少>,您需要使它成爲 ,也應該有不是。 最後,使用滾動視圖,您可能需要添加屬性android:fill_viewport =「true」,以便您的滾動視圖覆蓋整個屏幕。 – ootinii

+0

是的,編輯時錯過了,但現在應該可以正常工作:) – abhi

相關問題