WEB开发网
开发学院手机开发Android 开发 Android 使用Gallery实现图片“多级联动” 阅读

Android 使用Gallery实现图片“多级联动”

 2010-08-11 10:47:00 来源:WEB开发网   
核心提示:本文将讲解利用两个Gallery实现类似多级联动的功能,先看图: ,Android 使用Gallery实现图片“多级联动”,一个Gallery是歌曲专辑图片,另一个Gallery是专辑的歌曲,它很好的为某些组件提供了数据和view的实现,此处我们需要通过继承BaseAdapter,滑动专辑Gallery,下面的歌曲也会

本文将讲解利用两个Gallery实现类似多级联动的功能。先看图: ,一个Gallery是歌曲专辑图片,另一个Gallery是专辑的歌曲。滑动专辑Gallery,下面的歌曲也会随之发生变动。

device

一、布局。

主要的布局是有两个相对布局+两个Gallery组成的:

1: < ?xml version="1.0" encoding="utf-8"?>

2: < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

3: android:layout_width="fill_parent"

4: android:layout_height="fill_parent">

5: < !-- 专辑 -->

6: < Gallery android:id="@+id/gallery"

7: android:layout_width="fill_parent"

8: android:layout_height="wrap_content"

9: android:layout_alignParentTop="true"

10: android:gravity="center_horizontal"

11: android:spacing="16dp"

12: android:unselectedAlpha="0.5"/>

13: < !-- 歌曲 -->

14: < Gallery android:id="@+id/gallery2"

15: android:background="#FFF"

16: android:layout_width="fill_parent"

17: android:layout_height="30dp"

18: android:layout_below="@id/gallery"

19: android:layout_alignParentLeft="true"

20: android:gravity="center_vertical"

21: android:spacing="16dp"

22: android:unselectedAlpha="0.5" />

23: < /RelativeLayout>

二、Gallery的适配器

android中适配器很好的实现了MVC思想,它很好的为某些组件提供了数据和view的实现。此处我们需要通过继承BaseAdapter,实现两个Gallery的适配器。

1: /**

2: * 专辑

3: *

4: * @author halzhang

5: */

6: public class AlbumAdapter extends BaseAdapter {

7:

8: private Context context;

9:

10: private Cursor cursor;

1 2 3  下一页

Tags:Android 使用 Gallery

编辑录入:coldstar [复制链接] [打 印]
赞助商链接