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. python语言磁力搜索引擎源码公开,基于DHT协议

    原文地址: http://www.cnblogs.com/huangxie/p/5550680.html

  2. Struts2(三)——数据在框架中的数据流转问题

    一款软件,无在乎对数据的处理.而B/S软件,一般都是用户通过浏览器客户端输入数据,传递到服务器,服务器进行相关处理,然后返回到指定的页面,进行相关显示,完成相关功能.这篇博客重点简述一下Struts2 ...

  3. 那么温暖http合约,入门。

    简介 年提出.经过几年的使用与发展,得到不断地完好和扩展.眼下在WWW中使用的是HTTP/1.0的第六版,HTTP/1.1的规范化工作正在进行之中,并且HTTP-NG(Next Generation ...

  4. RMAN数据库恢复之丢失数据文件的恢复

    删除某一数据文件:SQL> HOST del D:\app\Administrator\oradata\orcl\USERS01.dbf 启动数据库,提示丢失数据文件4,此时数据库处理MOUNT ...

  5. Jvm垃圾回收堆内存变化过程

    当Eden区域满时,触发minor GC,垃圾收集器把Eden区域中的不可达对象标记出来.第一次执行minor GC时Survivor 1与Survivor 2均为空: Eden中的不可达对象占用的内 ...

  6. Android多媒体开发-stagefright及AwesomePlayer相关知识梳理

    android的多媒体框架中, stagefright其实是AwesomePlayer的代理,就是个皮包公司. status_t StagefrightPlayer::setDataSource( c ...

  7. Android多项目依赖在Eclipse中无法关联源代码的问题解决 Ctril 点不进去的解决方法

    1. 使用快捷键:Ctrl+shift+R,在弹出框中输入.classpath  找到被作为library引入的那个.classpath文件. 2.将kind="src" path ...

  8. sizeof 和 strlen

    1. sizeof 1.1 sizeof是一个独立的运算符,不是函数.sizeof给我们提供有关数据项目所分配的内存的大小.例如: 1 2 cout << sizeof(long) < ...

  9. Spring-----8、深入理解容器中的bean

    转载自:http://blog.csdn.net/hekewangzi/article/details/45648687

  10. CSS 垂直居中5种方法

    利用 CSS 来实现对象的垂直居中有许多不同的方法,比较难的是选择那个正确的方法.我下面说明一下我看到的好的方法和怎么来创建一个好的居中网站. 使用 CSS 实现垂直居中并不容易.有些方法在一些浏览器 ...