Android horizontal and vertical scrolling for GridLayout

I'm having trouble getting the GridLayout to scroll horizontally.

I found a similar question Gridlayout + ScrollView . I tried this method, but it did not work.

It cuts out many tables (because it had to display all tables from 1 to 20).

Here is the xml file

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:padding="16dp" > <android.support.v7.widget.GridLayout android:id="@+id/table_mapGrid" android:layout_width="250dp" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> <include layout="@layout/cell_list_loading" /> <TextView android:id="@+id/table_errorView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="20dp" android:text="@string/message_error_connection" android:visibility="invisible" /> </FrameLayout> 

I want dynamic content to display by changing the number of columns and rows, possibly with empty space between the tables. I did this, but the problem is that the width of the GridLayout is getting larger than its container, I wanted to solve using horizontal scrolling, but it does not seem to work ...

Any suggestion?

+6
source share
2 answers

Well, I found a solution

It seems that scrollView android works like a VerticalScrollView and only that (the name is not as intuitive as HorizontalScrollView).

So, to do something scrollable vertically and horizontally, you need to nest the (vertical) ScrollView in a HorizontalScrollView or vice versa, like this

 <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <HorizontalScrollView android:layout_width="wrap_content" android:layout_height="match_parent"> <!-- Your content here --> </HorizontalScrollView> </ScrollView> 
+9
source

The nested HorizontalScrollView / ScrollView will not allow you to scroll both directions at the same time. I had this problem and a special component was created for it, here is the link if it can help anyone:

https://gist.github.com/androidseb/9902093

+1
source

All Articles