If you want to have a Android Activity to be scrollable both horizontally and vertically be its any parent layout i.e LinearLayout, TableLayout, RelativeLayout or GridLayout, you can achieve it by making use of both HorizontalScrollView and ScrollView
Step 1: Choose your Parent layout. In the example I have choose a LinearLayout with with horizontal orientation.
Step 2: Add HorizontalScrollView as a sub-view with layout_width and layout_height as match_parent. You may add padding if you want.
Step 3: Within the HorizontalScrollView Add ScrollView as a sub-view with layout_width and layout_height as match_parent. You may add padding if you want.
Step 4: Now here you can all all the View elements that make up your Activity. To demonstrative i have added Two LinearLayouts with orientations vertical and horizontal respectively and added 10+ Button's to it.
Thats it! Try running the App and you would see that the View Scrolls both ways!
Source code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10px" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10px" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3" />
<Button
android:id="@+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 5" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 6" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 7" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 8" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 9" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 10" />
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 11" />
<Button
android:id="@+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 12" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/button111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:id="@+id/button21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3" />
<Button
android:id="@+id/button31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4" />
<Button
android:id="@+id/button121"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 5" />
<Button
android:id="@+id/button41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 6" />
<Button
android:id="@+id/button51"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 7" />
<Button
android:id="@+id/button61"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 8" />
<Button
android:id="@+id/button71"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 9" />
<Button
android:id="@+id/button81"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 10" />
<Button
android:id="@+id/button91"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 11" />
<Button
android:id="@+id/button101"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 12" />
<Button
android:id="@+id/button1121"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 13" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</HorizontalScrollView>
</LinearLayout>
- Check Internet Connection WIFI 4G is active on Android Programmatically
- Android Emulator cannot be opened because the developer cannot be verified. [M1 Mac]
- How to Change Android Toast Position?
- Fail to connect to camera service Android java RuntimeException
- How to create Custom RatingBar Android Programming Tutorial
- Fixing Android unknown error 961 while downloading app
- Android AlertDialog with Yes No and Cancel Button
- Share or Send SMS via Android Intent
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- Pass data between two Android Activities and access it using Intent
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- Android EditText Cursor Colour appears to be white
- Android Development - How to switch between two Activities
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Android : Remove ListView Separator/divider programmatically or using xml property
- Android is starting optimizing... app 1 of 1
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- AlertDialog with single button example : Android
- Android : Exception raised during rendering: action_bar API 22
- Maven : java.lang.ClassNotFoundException: Xmx512m
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Center align text in TextView Android Programming
- How to Download and Install Android adb Tool on Linux, Mac or Windows
- Multiline EditText in Android Example
- Fix: Sorry, we cant sync this folder, Youre already syncing a shortcut to a folder from this shared library [OneDrive] - Windows
- Know installed PowerShell Version on Mac - Powershell
- How to track and download Microsoft Teams meeting attendance report of participants/students - Teams
- reCAPTCHA Implementation Tutorial - CSS
- How to create Toast messages in Android? - Android
- How to get current URL Location using Javascript HTML - JavaScript
- Python: Replace the First Occurrence of String in a String - Python
- How to Show Path of Files or App in Mac Spotlight Search - MacOS