我正在为我的应用程序创建排行榜、高分列表。我想在 4 列中显示数据,Rank、Name、Creator、Score 并通过对象列表相应地填充它们。我想在列表上一次显示 5 个项目,列表中总共有 20 个项目,使列表可滚动。我找不到合适的方法来做到这一点。由于我的工作截止日期即将到来,如果我能获得有关“如何操作”的快速指南,那就太好了。
太感谢了 :)
您可以通过定义自定义 ListView 轻松完成。
要定义自定义列表视图,只需以水平方式定义一个带有 4 个文本视图的自定义行布局文件。现在在列表视图的自定义适配器中扩充此布局文件,为此您需要覆盖 getView() 方法并扩充该行布局文件。
更新: 只需查看本教程即可定义自定义列表视图,但请确保通过定义具有 4 个水平文本视图的自定义行布局文件来使用本教程。
这是row_layout.xml文件:
<LinearLayout
android:id="@+id/relativeLayout1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/FirstText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="First"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/SecondText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Second"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/ThirdText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Third"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/FourthText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Fourth"
android:layout_weight="1">
</TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21476 次 |
| 最近记录: |