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>
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
- How to open terminal on Mac to run commands - MacOS
- Change SharePoint search results FullTextSqlQuery RowLimit 10000 - SharePoint
- Calculate Area of Square - C-Program
- JSON Tutorial: List of Lessons - Json-Tutorial
- How to Subscribe to Google Nest Aware on iPhone - Google
- How to Connect to AWS Windows EC2 UI Instance from M1 Mac (Updated 2022) - HowTos
- How to uninstall GarageBand from Mac - MacOS
- How to hide or cancel Toast message in Android Programming - Android