mthoutai

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

AdapterView的子类的子类ListViewGridViewSpinnerGalleryAdapterViewFlipperStackView都是作为容器使用,Adapter负责提供各个列表项的内容。

 

 

1.列表视图ListViewListActivity

以垂直列表的形式显示列表项。

 

生成列表视图有例如以下两种方法:

(1).直接使用ListView

(2).Activity继承ListActivity

ListView支持的XML属性和相关方法:

Attribute Name

Related Method

Description

android:divider

 

设置List列表项的分隔条(颜色或Drawable

android:dividerHeight

 

设置分隔条的高度

android:entries

 

指定一个数组资源,用于填充列表的内容

android:footerDividersEnabled

 

设置为false。不在footer View前绘制分隔条

android:headerDividersEnabled

 

设置为false,不在header View后绘制分隔条

 

2.可展开的列表视图ExpandableListView

ExpandableListViewListView的子类,它把列表项分为几组,每组里包括多个列表项。

与其它列表视图不同的是:ExpandableListView的列表项应该由ExpandableListAdapter提供。

Adapter类似:ExpandableListAdapter也有三种经常使用方式:

(1).扩展BaseExpandableListAdapter实现ExpandableListAdapter

(2).使用SimpleExpandableListAdapter将两个List集合包装成ExpandableListAdapter

(3).使用SimpleCursorTreeAdapterCursor中的数据包装成SimpleCursorTreeAdapter

 

ExpandableListView支持的XML属性:

Attribute Name

Related Method

Description

android:childDivider

 

指定各组内子列表项之间的分隔条

android:childIndicator

 

显示在子列表项旁边的Drawable对象

android:groupIndicator

 

显示在组列表项旁边的Drawable对象

扩展BaseExpandableListAdapter实现ExpandableListAdapter的时候须要实现的4个方法:

getGroupCount():返回包括组列表项的数量

getGroupView():返回的View对象将作为组列表项

getChildrenCount():返回特定组包括的子列表项的数量

getChildView():返回的View对象将作为特定组、特定位置的子列表项

 

3.网格视图GridView

按行、列分布的方式显示多个组件。

 

GridView支持的XML属性和相关方法:

Attribute Name

Related Method

Description

android:columnWidth

setColumnWidth(int)

设置列的宽度

android:gravity

setGravity(int)

设置对齐方式

android:horizontalSpacing

setHorizontalSpacing(int)

设置各元素之间的水平间距

android:numColumns

setNumColumns(int)

设置列数

android:stretchMode

setStretchMode(int)

设置拉伸模式

android:verticalSpacing

setVerticalSpacing(int)

设置各元素之间的垂直间距

 

android:stretchMode:支持的属性:

NO_STRETCH:不拉伸

STRETCH_COLUMN_WIDTH:仅拉伸表格元素本身

STRETCH_SPACING:仅拉伸元素之间的间距

STRETCH_SPACING_UNIFORM:表格元素本身、元素之间的间距一起拉伸

 

4.列表选择框Spinner:

 

用下拉列表的形式显示列表项。

Spinner支持的XML属性和相关方法:

Attribute Name

Related Method

Description

android:dropDownHorizontalOffset

setDropDownHorizontalOffset(int)

设置选择框的水平偏移量

android:dropDownSelector

 

设定spinnerMode=”dropdown”时列表选择器的显示效果

android:dropDownVerticalOffset

setDropDownVerticalOffset(int)

设置选择框的垂直偏移量

android:dropDownWidth

setDropDownWidth(int)

设置选择框的宽度

android:gravity

setGravity(int)

设置对齐方式

android:popupBackground

setPopupBackgroundResource(int)

设置选择框的背景色

android:prompt

 

设置选择框的提示信息

android:spinnerMode

 

设置Spinner的显示模式

 

spinnerMode可选的属性:

dialog = 0:Spinner会被作为一个对口窗体来显示

dropdown = 1:Spinner会作为一个内嵌的下拉列表来显示

 

5.Gallery

显示一个水平的列表选择框。同意用户通过拖动来查看上一个、下一个。

Android推荐使用HorizontalScrollView和ViewPager组件来取代Gallery。

 

6.AdapterViewFlipper

继承自AdapterViewAnimator,AdapterViewFlipper每次仅仅能显示Adapter中的一个列表项。程序通过showPrevious()和showNext()方法来显示上一个、下一个列表项。组件切换时能够自己主动动画效果。

还有startFlipper()方法用于自己主动播放下一个列表项。

AdapterViewAnimator支持的XML属性和相关方法:

Attribute Name

Related Method

Description

android:animateFirstView

 

设置显示第一个列表项时是否使用动画

android:inAnimation

 

设置组件显示时使用的动画

android:loopViews

 

设置循环究竟是否转头到第一个列表项

android:outAnimation

 

设置组件隐藏时使用的动画

 

AdapterViewFlipper支持的XML属性和相关方法:

Attribute Name

Related Method

Description

android:autoStart

startFlipping()

设置该组件是否自己主动播放

android:flipInterval

setFlipInterval(int)

设置自己主动播放的时间间隔

 

7.StackView

继承自AdapterViewAnimator,StackView把列表项“堆叠”在一起,以这样的方式显示列表项。程序通过showPrevious()和showNext()方法来显示上一个、下一个列表项。

列表项切换时出现的是堆叠一起的卡片会出现的动画效果。

 

 

 

 

posted on 2017-06-13 14:11  mthoutai  阅读(201)  评论(0编辑  收藏  举报