给ListView设置分割线,只需设置如下两个属性:

android:divider="#000" //设置分割线显示颜色

android:dividerHeight="1px" //此处非0,否则无效

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <ListView        android:id="@+id/listview"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:divider="#0f0"        android:dividerHeight="1dp" /></RelativeLayout>
代码如下:

package com.itfom.listviewdivider;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;public class MainActivity extends Activity {private ListView listview;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);listview = (ListView) findViewById(R.id.listview);//绑定适配器ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{"夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊","夏守成好帅啊"});listview.setAdapter(adapter);}}

运行结果如下所示:



更多相关文章

  1. wheelView自定义android日期时间选择器
  2. android之【本地通知Notification】
  3. Android之省市县三级联动
  4. Android(安卓)ViewPager实现图片 小圆点切换
  5. Android中GPS/Map的运用
  6. android 怎样用代码设置墙纸
  7. android dialog
  8. 开源项目Universal Image Loader for Android(安卓)说明文档 (2)
  9. Android文件读写简单示例

随机推荐

  1. 读研or工作?
  2. 被敖丙用烂的「数据库调优」连招?真香,淦!
  3. Docker容器--安装部署
  4. web前端开发就业前景怎么样?
  5. 流式数据处理在百度数据工厂的应用与实践
  6. 单机训练速度提升640倍!独家解读快手商业
  7. VUE学习之常用指令2
  8. php get_class_methods('myclass') 获
  9. 闪存显示提示格式化怎样办
  10. Linux运维入门教程06-03 (硬盘分区、格式