开发者

Scrollview to scroll table both horizontally and vertically in android

开发者 https://www.devze.com 2023-01-16 04:16 出处:网络
In my android application i am using a table inside a scrollview but am not able to scroll horizontally if the length of content is more.

In my android application i am using a table inside a scrollview but am not able to scroll horizontally if the length of content is more. Could y开发者_Python百科ou please let me know any solution for this?

Thanks in advance:)


XML layout:

<ScrollView ...>

    <HorizontalScrollView ...>

        YOUR TABLE HERE

    </HorizontalScrollView>

</ScrollView>


Another option is by using GridView

  1. Use a horizontal scroll view to contain the GridView
  2. Then dynamically re-size the GridView width based on the number of columns that you set for the GridView
  3. Lastly, multiply number of columns with the width of each columns

    GridView gridView = (GridView) findViewById(R.id.grid_view);
    int numberOfColumns = 3;
    int sizeOfWidthPerColumn = 20;
    gridView.setNumColumns(numberOfColumns);
    ViewGroup.LayoutParams layoutParams = gridView.getLayoutParams();
    layoutParams.width = convertDpToPixels(numberOfColumns * sizeOfWidthPerColumn, this);
    gridView.setLayoutParams(layoutParams);
    

Now I am able to scroll the GridView horizontally and vertically.

0

精彩评论

暂无评论...
验证码 换一张
取 消