Gallery本地开发是一个相对简单的例子,下面将讲棕此例子开发的过程与代码!

  首先main.xml文件的代码:

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <Gallery
7 android:id="@+id/gallery"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 >
11 </Gallery>
12 </LinearLayout>

  MainActivity.java:

View Code

  ImageAdapter.java

View Code

  在ImageAdapter中,本地图片的获取是有点复杂的,由于Android系统架构,可以直接调用Android系统里的资源,本文用到的是ContentResolver,通过ContentResolver来获得Cursor,但如何通过Cursor取出图片,从官方文档中找到Cursor中取出_ID并转成图片的方法。具体转自:http://www.cnblogs.com/chiefCTO/articles/2180247.html

posted on 2011-09-21 20:25  Conerlius  阅读(413)  评论(2编辑  收藏  举报