【问题标题】:Separating Android Lists with Headers用标题分隔 Android 列表
【发布时间】:2011-05-11 18:01:47
【问题描述】:

好的,我这几天一直在寻找。我一直在寻找人们为实现这一目标而制作的自定义类。特别是 Jeff Sharkey's class 和 Commonsware 类。

我注意到 Jeff Sharkey 在 2008 年发表了这篇文章。现在那是不久前的事了。谷歌是否集成了一种无需使用自定义类的方法?我真的很想不必使用自定义类,只需坚持使用 java/android sdks

【问题讨论】:

    标签: android list listview header separator


    【解决方案1】:

    我有一个 twolinelistview.xml,其中有 2 个文本视图。我用常规数据填充底部文本,用标题数据填充顶部文本。空的标题项不会给我带来任何问题。

    public static class ViewHolder {
        TextView toptext;
        TextView bottomtext;
    }
    

    XML:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <TextView 
            android:id="@+id/lv_topText"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textColor="@drawable/ltGrey" 
            android:background="@drawable/semiTransparentDrk"
            android:textSize="24sp" 
            android:typeface="sans" 
            android:textStyle="bold" 
            android:ellipsize="end"
            android:scrollHorizontally="true"
            android:padding="10sp"/>
        <TextView 
            android:id="@+id/lv_bottomText"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textColor="@drawable/ltGrey" 
            android:background="@drawable/semiTransparentDrk"
            android:textSize="18sp" 
            android:typeface="sans" 
            android:textStyle="bold"
            android:ellipsize="end"
            android:scrollHorizontally="true"
            />
    </LinearLayout>
    

    【讨论】:

    • 我想我会坚持 Jeff Sharkey 的课程。我发现它比这更容易实现。感谢您的回复
    • 在您发表评论之前,我没有看他的例子。你无法击败一个完整的代码示例;)干杯。
    【解决方案2】:

    没有。 Google 提供的 SDK 包含具有足够可扩展性的基本组件,以允许开发人员利用现有的工作来创建自己的组件,而无需做大部分困难的事情。

    列表标题之类的东西也不是那么难,Google 确实不需要将其添加到 SDK 中。

    如果您想要避免每次使用项目时都重新制作组件,那么请在 Android 库项目中设置您喜欢的类。还有一些库包含具有额外功能的组件,例如 Green Droid 等。

    【讨论】:

    • List headers 对于学java一段时间的人来说可能不难,但对于只学了一周的人来说却是相当困难。幸运的是,我的背景中有很多 actionscript、javascript 和 php,所以克服它并没有太大的障碍。我仍在努力寻找解决日食的方法:D。我明白你的意思。我去看看绿色机器人。
    猜你喜欢
    • 1970-01-01
    • 2015-07-06
    • 2013-11-22
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    • 2018-01-23
    相关资源
    最近更新 更多