Android ListView with complex title

I am trying to add a complex / nontrivial header to a ListView (and a slightly less complex footer) that should scroll along with the rest of the content.

The header consists of

  • Bold TextView with black transparent background and rounded corners.
  • TextView with plain text, black transparent background
  • Imageview
  • click button (actually ImageView with onClick) and delimiter

I am familiar with addHeaderView, but if I try to add a complex view (consisting of LinearLayout with several children), I see only the first child of the complex title in the list as a title.

In addition, the design breaks down (because the title may be transparent, the ListView itself is missing. Perhaps this can be solved by adding more styles to the ListView itself and its entries (which should not be transparent), but I get the impression that I just achieve the limits of listviews.

Can this be done? Does anyone know of any applications (or better, code examples) that have a similar complex title? All the other examples I could find are trivial headers: buttons, text images or images (online and on SO) with hardly any interesting style.

+6
android styling listview header
source share
2 answers

I tried to override my scroll list from scratch, like this:

  • main.xml with a background image and one ListView with a 20dip mark and a specific style:

    <item name="android:cacheColorHint">#00000000</item> <item name="android:scrollbars">@null</item> <item name="android:background">@android:color/transparent</item> 
  • headerlayout.xml containing a linear layout (vertical) containing TextView, ImageView, and another TextView. The first TextView is decorated with rounded vertices, both text and transparent, and click on the image.

  • (similar footer style)
  • A custom entry for each list with a solid white background.

Headers / footers are added approximately as follows

 ListView list = (ListView) findViewById(R.id.list); View header1 = getLayoutInflater().inflate(R.layout.listheader, null, false); View footer = getLayoutInflater().inflate(R.layout.listfooter, null, false); ImageView image = (ImageView) header1.findViewById(R.id.image); list.addHeaderView(header1, null, false); list.addFooterView(footer, null, false); list.setAdapter(new MenuAdapter()); 

None of this is really special. It is basically a question of how to do things in the correct order, to undress and to style correctly.

+5
source share

My suggestion is that you create a custom view for this too complex list item. Apparently, this is what Android developers at Google IO also suggested. If you can do this in user mode, all your problems will be resolved.

0
source share

All Articles