How can I make my layout scroll both horizontally and vertically?
I was able to find a simple way to achieve both scrolling behaviors.
Here is the xml for it:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical">
<HorizontalScrollView
android:layout_width="320px" android:layout_height="fill_parent">
<TableLayout
android:id="@+id/linlay" android:layout_width="320px"
android:layout_height="fill_parent" android:stretchColumns="1"
android:background="#000000"/>
</HorizontalScrollView>
</ScrollView>
How to make layout scrollable both horizontally and vertically?
ScrollView
and HorizontalScrollView
are layout container for a view hierarchy
that can be scrolled vertically or horizontally by the user, allowing it to be larger than the physical display. A ScrollView/HorizontalScrollView
is a FrameLayout
, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects.
Here is xml :
<?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"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Inside 1st HorizontalScrollView" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button A1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button A2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button A3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button A4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button A5" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Inside 2nd HorizontalScrollView" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button B1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button B2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button B3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button B4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button B5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button B6" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Inside ScrollView" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button C" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button D" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button E" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button F" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button G" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button H" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button I" />
</LinearLayout>
</ScrollView>
</LinearLayout>
for more detail visit this : http://android-coding.blogspot.in/2011/01/scrollview-and-horizontalscrollview.html
Update :
use this xml to scroll vertical
as well as horizontal
.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320px" android:layout_height="fill_parent">
</HorizontalScrollView>
</ScrollView>
How to make relative layout scroll vertically/horizontally?
Your problem is this:
android:layout_alignParentBottom="true"
You are telling the OS to anchor this view to the bottom of the screen, and some views are laid above this one. This forces everything to fit in a single screen.
You need to replace your RelativeLayout with a LinearLayout with vertical orientation and then lay things out in order, from top to bottom.
Related Topics
Android Edittext - Finished Typing Event
How to Make an Android Slidingdrawer Slide Out from the Left
Can't Run a Java Android Program with Valgrind
How to Browse Localhost on Android Device
Android Countdowntimer - Additional Milliseconds Delay Between Ticks
Programmatically Adding Tablerow to Tablelayout Not Working
Adding Google Play Services Version to Your App's Manifest
How to Detect Orientation of Android Device
How to Achieve Gapless Audio Looping So Far on Android
Multiple Instances of Widget Only Updating Last Widget
Removing a Fragment from the Back Stack
How to Change Default Images of Checkbox
Google Places API Request Denied for Android Autocomplete, Even with the Right API Key
How to Restrict the Edittext to Accept Only Alphanumeric Characters
How to Change Text in Android Textview
Nullpointerexception When Trying to Access Views in a Kotlin Fragment