带有复杂标题的 Android ListView [英] Android ListView with complex header

查看:20
本文介绍了带有复杂标题的 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
  • 一个图像视图
  • 一个可点击的按钮(实际上是一个带有 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 本身及其条目(不应该是透明的)添加更多样式来解决这个问题,但是我的印象是我在这里达到了 ListViews 的限制.

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.

这可以吗?有谁知道具有类似复杂标头的任何应用程序(或更好的代码示例)?我能找到的所有其他示例都是微不足道的标题:按钮、文本视图或图像(在线和 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>

  • 包含一个线性布局(垂直)的 headerlayout.xml,包含一个 TextView、ImageView 和另一个 TextView.第一个 TextView 的样式是圆角顶角,两个 textview 的样式都是透明的,并且在图像上有一个 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.

    header/footer的添加大致如下

    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天全站免登陆