ListView是一个可以在垂直滚动的列表中显示的一个控件,条目的内容来自一个ListAdapter。
由于ListAdapter是一个有很多参数的接口,所以直接去实现它就很麻烦,一般是直接去继承BaseAdapter类。
下面说正题。
在安卓应用中,一般的新闻展示可以用ListView控件来实现,先看效果。新闻内容只弄三个,其它就直接 for 100次了,所以很多重复的,图片是我在网上随便选的,别在意。。。
右图是我的目录结构。
首先是在activity_main.xml中加入ListView控件。
1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context="news_listview.starry.cn.a3listview.MainActivity"> 8 9 <ListView 10 android:id="@+id/lv_news" 11 android:layout_width="fill_parent" 12 android:layout_height="fill_parent" 13 /> 14 15 </android.support.constraint.ConstraintLayout>