Android的ListView的复杂头 [英] Android ListView with complex header

查看:120
本文介绍了Android的ListView的复杂头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个复杂的/不平凡的标头添加到一个ListView(略不太复杂的页脚),需要与其他内容一起滚动。

I'm trying to add a complex / non-trivial header to a ListView (and slightly less complex footer) that needs to scroll along with the rest of the content.

头包括

  • 用粗体文字,黑色透明的背景和圆角一个TextView
  • 在对普通的文字一个TextView,黑色透明背景
  • 在一个ImageView的
  • 在一个可点击的按钮(实际上有一个的onClick ImageView的)和一个分频器

我熟悉addHeaderView,但如果我尝试添加一个复杂的视图(包括与多个孩子的LinearLayout的),我只看到了复杂的头的第一个孩子在ListView的头。

I'm familiar with addHeaderView, but if I try to add a complex view (consisting of a LinearLayout with multiple children), I only see the first child of the complex header in the listview as header.

此外,该设计突破(因为头可以被透明样式,ListView控件本身是没有的。也许,这可以通过添加更多的造型给ListView本身及其项(这不应该是透明的)来解决,但我有IM pression我只是达到列表视图限制在这里。

Also, the design breaks (because the header may be styled transparently, the ListView itself isn't. Perhaps this can be solved by adding more styling to the ListView itself and its entries (which shouldn't be transparent), but I have the impression I'm simply reaching ListViews limits here.

可以这样做?没有人知道有一个类似的复杂头的任何应用程序(或更好,code的例子)?我已经能够找到其它的例子是平凡的标题:按钮,textviews或图像(在网上和SO),几乎没有有趣的造型

Can this be done? Does anyone know of any applications (or better, code examples) that have a similar complex header? All other examples that I've been able to find are trivial headers: buttons, textviews or images (online and on SO) with hardly interesting styling.

推荐答案

我试图重新实现从无到有我的滚动列表视图,大体如下:

I've attempted to reimplement my scrolling listview from scratch, roughly as follows:

  • 与背景图像和一个ListView的一个main.xml中,有20dip缘 一些特定的样式:

  • a main.xml with a background image and a single ListView, with a 20dip margin and some specific styling:

<item name="android:cacheColorHint">#00000000</item>
<item name="android:scrollbars">@null</item>
<item name="android:background">@android:color/transparent</item>

  • 含有线性布局(垂直),包含一个TextView,ImageView的,另一个TextView的一个headerlayout.xml。第一个TextView的是风格与圆润topcorners,既textviews都是透明的风格,并在图像上clicklistener。

  • a headerlayout.xml containing a linear layout (vertical), containing a TextView, ImageView and another TextView. The first TextView is styled with rounded topcorners, both textviews are styled transparent, and a clicklistener on the image.

    的页眉/页脚大致加入如下

    The header/footer are added roughly 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 actually truely special. It's mostly a matter of doing things in the right order, stripped down and properly styled.

    这篇关于Android的ListView的复杂头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆