1:

xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<Gallery
        android:id="@+id/imagegallery"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" />

</LinearLayout>

2:

java文件

package com.example.cloud.hdplayer2.faq;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ImageShowActivity extends Activity {
private Gallery imagegallery;
private ImageView image;
private String pos;
private ImageAdapter imageadapter;
private int[] images = new int[] { R.drawable.m1, R.drawable.m2,
R.drawable.m3, R.drawable.m1, R.drawable.m1, R.drawable.m1,
R.drawable.m1 };

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imageshow);

imagegallery = (Gallery) findViewById(R.id.imagegallery);
imageadapter = new ImageAdapter(getApplicationContext());
initview();
}

private void initview() {
imagegallery.setAdapter(imageadapter);
imagegallery.setSelection(0);

}

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context context) {
mContext = context;
}

public int getCount() {
return images.length;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
ImageView image = new ImageView(mContext);
image.setImageResource(images[position]);
image.setAdjustViewBounds(true);
image.setLayoutParams(new Gallery.LayoutParams(  
           LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return image;
}
}

}

android gallery的使用的更多相关文章

  1. ios 仿android gallery控件

    ios 上没有发现与android gallery类似的控件,因为在项目上须要使用到.採用UICollectionView实现 watermark/2/text/aHR0cDovL2Jsb2cuY3N ...

  2. Android Gallery

    xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...

  3. Android——Gallery 图片拖动效果

    1.XML文件 <?xml version="1.0" encoding="utf-8"?><Gallery xmlns:android=&q ...

  4. android gallery 自定义边框+幻灯片

    最近在项目中用到图片轮播,试了Gallery,ViewFlipper,ViewPager,感觉Gallery最符合需求,但是Gallery的系统边框很难看,项目中要求用自己的背景图片. 下面来看一下使 ...

  5. android Gallery滑动不流畅的解决

    import android.content.Context; import android.util.AttributeSet; import android.view.KeyEvent; impo ...

  6. Android Gallery实现3D相册(附效果图+Demo源码)

    今天因为要做一个设置开机画面的功能,主要是让用户可以设置自己的开机画面,应用层需要做让用户选择开机画面图片的功能.所以需要做一个简单的图片浏览选择程序.最后选用Gallery作为基本控件.加入了一些炫 ...

  7. Android之循环显示图像的Android Gallery组件

    转自:http://www.blogjava.net/nokiaguy/archive/2010/08/23/329721.html Gallery组件主要用于横向显示图像列表,不过按常规做法.Gal ...

  8. android gallery 自定义边框+幻灯片效果

    最近在项目中用到图片轮播,试了Gallery,ViewFlipper,ViewPager,感觉Gallery最符合需求,但是Gallery的系统边框很难看,项目中要求用自己的背景图片. 下面来看一下使 ...

  9. Android Gallery和ImageSwitcher同步自动(滚动)播放图片库

    本文主要内容是如何让Gallery和ImageSwitcher控件能够同步自动播放图片集 ,看起来较难,然而,实现的方法非常简单, 请跟我慢慢来.总的来说,本文要实现的效果如下图:(截图效果不怎么好) ...

随机推荐

  1. poj 1753 Flip Game(bfs状态压缩 或 dfs枚举)

    Description Flip game squares. One side of each piece is white and the other one is black and each p ...

  2. Java Base64编码与图片互转

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...

  3. Kolor Neutralhazer v1.0.2 (照片雾气模糊去除过滤器)+破解RI

    由于空气污染.阴霾几天越来越,根据照片始终是一个灰色,怎么做?有了这个插件.能够解除您的烦恼. Neutralhazer这是消除你的风景照片和雾气模糊的全景图的有效途径photoshop小工具. wa ...

  4. 【set&&sstream||floyed判环算法】【UVa 11549】Calculator Conundrum

    CALCULATOR CONUNDRUM Alice got a hold of an old calculator that can display n digits. She was bored ...

  5. LINQ 基本子句之二 join

    Join子句据说可以实现3中连接关系. 1.内部连接——元素的连接关系必须同时满足被连接的两个数据源 2.分组连接 3.左外连接 1.最基本的,内部连接,类似于sql中inner join. 由于st ...

  6. Sharepoint2010 通过 WebFeature 修改web.config

    using System;using System.Runtime.InteropServices;using System.Security.Permissions;using Microsoft. ...

  7. 《JavaScript 闯关记》之数组

    数组是值的有序集合.每个值叫做一个元素,而每个元素在数组中有一个位置,以数字表示,称为索引. JavaScript 数组是无类型的,数组元素可以是任意类型,并且同一个数组中的不同元素也可能有不同的类型 ...

  8. sql 函数 总结

    聚合函数 Avg(numeric_expr)返回integer.decimal.money.float---返回组中各值的平均值 Count(*|column_name|distinct column ...

  9. 世界国家名与英文名【json】

    英文版 var geolocation= [   ["AO", "Angola"],   ["AF", "Afghanistan& ...

  10. slf4j 和 log4j使用案例

    以Maven项目为例: 步骤: 1.在Maven的pom.xml文件中添加dependency: 之后就会添加3个jar包: 2.在项目下添加log4j.properties  3.log4j.pro ...