7.11. Gallery组件(拖拉组件)
对于许多使用过Android手机的用户应该知道,在Android中可以使用一些软件方便的进行图片的拖拽浏览,
这样的功能就可以通过Gallery实现,使用Gallery组件可以定义一组图片浏览框,可以减轻开发者对于图片
浏览开发的功能的开发困难。
它的继承结构如下:
|
在使用Gallery设置图片集的时候需要使用setAdapter()方法,此时设置的SpinnerAdapter接口的对象,主
要的功能是定义一组要显示的组件的适配器,而对于这种适配器操作有两种可选方式:
- 方式一:用一个自定义的类直接继承SpinnerAdapter接口的子类----android.widget.BaseAdapter类实现,
这样用户只需要覆写核心操作方法即可,不需要的方法可以不用覆写。
- 方式二:直接使用之前学习过的SpinnerAdapter类完成。
SpinnerAdapter接口:
public interface SpinnerAdapter implements Adapter
|
已知子类:
Known Indirect Subclasses ArrayAdapter<T>, BaseAdapter, CursorAdapter, ResourceCursorAdapter, SimpleAdapter, SimpleCursorAdapter |
范例一:使用BaseAdapter
配置文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/MyLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Gallery android:id="@+id/myGallery" android:gravity="center_vertical" android:spacing="3px" android:layout_width="fill_parent" android:layout_height="wrap_content"/ |