How to add a scroll view for all activity?

I tried adding a scroll around everything on the activity layout, but that gave me an error saying that it can only be placed on one thing.

My activity has a text image of the title, then an image, then a text representation of the description, and you cannot read the entire description because it is long and goes below the edge of my screen. How can I make a scrollable face?

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> 
+6
source share
4 answers

Try the following:

 <?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> 
+27
source

Wrap LinearLayout ( LinearLayout height) with a SrollView ( fill_parent height).

+1
source

One is your LinearLayout . Just wrap this in a ScrollView , and you encapsulate the layout for the whole action.

Also, if you want to wrap only one elemtnet element in a ScrollView , all you have to do is put that element in your own layout, like a linear or relative layout, and then it will become one of the elements of your ScrollView

0
source

just use it

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

Source: https://habr.com/ru/post/947675/


All Articles