Is there a way to force GridView to only be a single row? Right now by default it will extend its height to accommodate all v开发者_JAVA技巧iews supplied by its adapter
You Should combine a horizontal SCROLLVIEW and a LINEARLAYOUT and a GRIDVIEW to achieve what you want! put grid view in linearlayout and put the linear layout in the horizontal scroll view;
then when setting adapter! count the number of data! after that you should calculate the desired width to show all your items! for example you want to show 8 item! each width is 100dp . so the desired width would 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 the xml!
*** IMPORTANT NOTE
as i know, by doing this, gridview can't garbage collection because Scroll View doesn't support such a thing and your grid view nested in it! so dnt use this method for lots of images or you will get HEAP SIZE error!
精彩评论