You must combine horizontal SCROLLVIEW and LINEARLAYOUT and GRIDVIEW to achieve what you want! place the grid in linearlayout and place the linear layout in the horizontal scroll view;
then when setting up the adapter! count the amount of data! after that you must calculate the desired width to show all your items! For example, you want to show 8 items! each width is 100dp. so the desired width will be 800dp! then you should add these lines of code
yourGridView.setNumColumns(8);
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(800, ViewGroup.LayoutParams.MATCH_PARENT);
yourGridView.setLayoutParams(lp);
dnt forget to set the width of the linear layout as WRAP_CONTENT in xml!
*** IMPORTANT NOTE
as I know, having done this, gridview cannot collect garbage, because Scroll View does not support such a thing, and your mesh view is embedded in it! therefore dnt use this method for a large number of images or you will get a HEAP SIZE error!
source
share