I can not scroll down the screen to view the data in the "Replied By:" section. How can I make my layout scrollable?
You cannot make a LinearLayout scrollable because it is not a scrollable container. Only scrollable containers such as ScrollView, HorizontalScrollView, ListView, GridView, ExpandableListView can be made scrollable.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In this above code, we have declare Linear layout as parent and added Vertical Scroll view.
Just wrap all that inside a ScrollView
:
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- Here you put the rest of your current view--> </ScrollView>
As David Hedlund said, ScrollView
can contain just one item... so if you had something like this:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- bla bla bla--> </LinearLayout>
You must change it to:
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- bla bla bla--> </LinearLayout> </ScrollView>
For using scroll view along with Relative layout :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen --> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/background_image" > <!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. --> </RelativeLayout> </ScrollView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With