欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android組件ListView列表簡(jiǎn)單使用

 更新時(shí)間:2017年02月06日 09:20:23   作者:DTCTCM  
這篇文章主要為大家詳細(xì)介紹了Android組件ListView列表的簡(jiǎn)單使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

ListView是一種非常常見(jiàn)的一個(gè)組件,以垂直列表的形式顯示列表項(xiàng)。而完成一個(gè)簡(jiǎn)單的ListView只需要這么三個(gè)步驟:

1、在布局文件XML中添加ListView并配置相應(yīng)的屬性
2、在資源文件XML中添加列表項(xiàng)
3、將布局文件應(yīng)用上

舉例:

1、在布局文件中加ListView并配置相應(yīng)屬性,如下配置了寬度、高度、分割線高度、是否顯示頭部分割線、列表項(xiàng)

<?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="match_parent" 
 android:orientation="vertical"> 
 
 <ListView 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" 
  android:dividerHeight="5px" 
  android:headerDividersEnabled="false" 
  android:entries="@array/list"/> 
 
</LinearLayout> 

2、資源文件XML中添加列表項(xiàng),新建XML文件,命名為arrays.xml,存放于Values文件夾中(開(kāi)發(fā)環(huán)境為Android Studio)

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 <string-array name="list"> 
  <item>列表項(xiàng)1</item> 
  <item>列表項(xiàng)2</item> 
  <item>列表項(xiàng)3</item> 
  <item>列表項(xiàng)4</item> 
  <item>列表項(xiàng)5</item> 
  <item>列表項(xiàng)6</item> 
  <item>列表項(xiàng)7</item> 
 </string-array> 
</resources> 

 3、在MainActivity中應(yīng)用布局文件,即可顯示列表項(xiàng)

這樣就完成了一個(gè)最最簡(jiǎn)單的列表。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論