0
A
回答
2
- 用于小区创建一个布局XML
- 对于行
- 创建一个布局XML在其中定义行(头)和低于 3.A. ListView中创建一个布局XML或者,您可以使用ListView的addHeaderView(View v)方法
- 创建自定义适配器并覆盖getView方法。检查每隔一行(位置%2 == 0)并更改行的颜色
我做了一个示例项目,可以从here下载它。
1)创建一个单元的布局XML
RES /布局/ cell.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="4dp"
android:background="@drawable/item_light_bg"
/>
如果你希望你的行是相同的宽度指定layout_width = “0dp” 和layout_weight = “1”。
2.),用于一个行创建一个布局XML
RES /布局/ list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="@+id/firstCol"
layout="@layout/cell"
/>
<include
android:id="@+id/secondCol"
layout="@layout/cell"
/>
<include
android:id="@+id/thirdCol"
layout="@layout/cell"
/>
<include
android:id="@+id/fourthCol"
layout="@layout/cell"
/>
<include
android:id="@+id/fifthCol"
layout="@layout/cell"
/>
</LinearLayout>
3.)创建一个布局XML在其中定义行(头)和这
RES /布局/ main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include
android:id="@+id/header"
layout="@layout/list_item"
/>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
4)下面的ListView控件创建自定义适配器和奥雅纳使用getView方法。检查是否为每隔一行(位置%2 == 0),并更改行的颜色
public class MyAdapter extends SimpleAdapter {
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout v = (LinearLayout)super.getView(position, convertView, parent);
if (position % 2 == 0)
v.setBackgroundColor(Color.rgb(0, 0, 55));
else
v.setBackgroundColor(Color.rgb(22, 22, 88));
return v;
}
...
此外,您可能需要您的ListView是静态的(例如,不可点击和选择)。为此,请覆盖适配器中的isEnabled方法。
@Override
public boolean isEnabled(int position) {
return false;
}
相关问题
- 1. android布局 - 滚动视图不显示
- 2. Android Default列表视图行布局
- 3. Android列表视图行布局
- 4. Android的列表视图布局
- 5. 上载到列表视图:Android布局
- 6. Android的列表视图布局优化
- 7. Android自定义列表视图布局到另一个布局
- 8. 警报视图显示我警告
- 9. 用于显示列表视图的布局错误
- 10. 在drupal的合成布局中显示“视图”列表
- 11. 如何在列表视图布局中显示结果?
- 12. Admob显示在标签布局的列表视图
- 13. Eclipse - 在Android视图的图形布局中显示布局指南(线条)
- 14. 在Android中动态加载列表视图时布局不正确显示?
- 15. SSRS报告自定义提示布局
- 16. Android的布局 - 不显示图像视图
- 17. Android - 用于显示空白列表视图的显示警报对话框
- 18. 使用图表显示报告
- 19. Adwhirl的报告没有显示图表
- 20. 表布局视图
- 21. 列表视图不显示在android?
- 22. 显示子报告报告
- 23. Android GridMenu布局 - 图像未显示
- 24. 水晶报告布局
- 25. oracle报告布局问题
- 26. Android CrossFader显示布局
- 27. Android ExpandableListAdapter视图布局不按要求显示:-(
- 28. 如何强制android布局显示两个视图
- 29. 如何在布局中显示视图Android Xamarin c#
- 30. 列表视图中itemview的表格布局android performance
这是我想要的东西,非常感谢你对此的解释和代码 – 2011-06-09 05:38:27
示例项目链接是死的(http://dl.dropbox.com/u/296580/Test.zip) – 2015-04-15 05:30:10