How to add a scroll view to an entire activity?
38,708
Solution 1
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>
Solution 2
Wrap the LinearLayout
(height is wrap_content
) with SrollView
(height is fill_parent
).
Author by
Mike
Updated on March 06, 2020Comments
-
Mike about 4 years
I tried adding a scroll view around everything on an activity layout but it gave me an error saying it can only be placed around one thing.
My activity, has a title textview then an image, then a description text view, and you can not read the whole description because its to long and goes below the edge of my screen. How can I make the whoel thing scrollable?
My xml looks like this:
<?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>
-
Mike almost 11 yearsat the linear layout line I am getting this error: Multiple annotations found at this line: - Element type "ScrollView" must be followed by either attribute specifications, ">" or "/>". - error: Error parsing XML: not well-formed (invalid token)
-
ootinii almost 11 yearsIt's missing the >, you need to make it <ScrollView xmlns:android="schemas.android.com/apk/res/android" android:id="@+id/scrollview" android:layout_width="fill_parent" android:layout_height="wrap_content">, also the end there should be </ScrollView> not <ScrollView/>. Finally, with scrollviews, you may want to add the attribute android:fill_viewport="true" so your scrollview covers the whole screen.
-
abhi almost 11 yearsyes that was missed at edited time but it should work fine now :)