How do I call 2 consecutive items in a list in a table form next to each other?

瘦欲@ 提交于 2019-12-02 12:01:49

What this essentially boils down to is finding a compromise between:

  1. A ListView (where you're stuck with individual rows) or GridView (where there are a fixed number of non-spannable columns), or
  2. A fixed layout in the form of a TableLayout or a GridLayout.

Clearly, the first options won't suffice out of the box, because you want some rows with one column and others with two. You may find a compromise in writing your own implementation of a ListView, but this will be extremely tedious and most likely overkill for your application.

I'm aware of a custom component that allows for staggered columns (StaggeredGridView), but you'd instead need column spanning. Perhaps there's another open source custom component out there somewhere that gets this done.

The second option--writing a fixed layout in a TableLayout or a GridLayout--probably won't suit your needs either as the length of your list is dynamic, layouting would be slow, and loading images into the placeholders will consume a considerable amount of memory.

I would instead suggest using a ListView and writing a custom list adapter that inflates different layouts. Those layouts should include ViewGroups that handle the click event instead of having that done through the ListView's own OnItemClickListener. Perhaps you could have two layouts:

  • One headline layout, that is essentially one layout that spans the entire width;
  • One multi-item layout, that displays two news items next to one another with equal weights.

This does mean that you'll need to provide a custom background with selector states and handle the OnClickListener of the individual ViewGroups yourself, but it also allows you to make good use of layouts in for different screen sizes. By using <include> you can consider, for instance, displaying three news items next to each other for res/layout-land or res/layout-w720dp. Perhaps in the case of three columns you could even mix things up a little with a two-column span for articles with image, and single columns for articles without.

Yes you can use the gridView for this one. here is the example codes

just check link1 and link2

Use grid view. make it auto fit fellow same approach get getItemViewType return large item for first. and rest small. I think this should work, never tried this.

or refer http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-first-item-of.html similar to your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!