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. UVA - 10129 Play on Words(欧拉回路+并查集)

    2.解题思路:本题利用欧拉回路存在条件解决.可以将所有的单词看做边,26个字母看做端点,那么本题其实就是问是否存在一条路径,可以到达所有出现过的字符端点.由于本题还要求了两个单词拼在一起的条件是前一个 ...

  2. IOS拷贝文件到沙盒

    - (void)copyFileFromResourceTOSandbox { //文件类型 NSString * docPath = [[NSBundle mainBundle] pathForRe ...

  3. [Node.js]在windows下不得不防的小错误

    TypeError: Arguments to path.join must be strings at f (path.js:204:15) at Object.filter (native) at ...

  4. LINQ To XML的一些方法

    1.Elements() 返回XML文档或片段的所有第一级元素. 2.Descendants() 返回XML文档或片段中的所有子元素(所有级别的子元素). 3.Attributes() 返回当前选中元 ...

  5. QUdpSocket Class

    翻译自:QT官网文档QUdpSocket类 QUdpSocket类提供一个UDP套接字. Header: #include <QUdpSocket> qmake: QT += networ ...

  6. Android默认启动程序问题

    参考地址:http://www.cnblogs.com/Lewis/p/3316946.html 怎么让我们自己开发的Android程序设为默认启动呢?其实很简单,只要在AndroidManifest ...

  7. 【web开发--js学习】functionName 如果是一个属性值,函数将不会被调用

    <html> <head> <meta http-equiv="Content-Type" Content="text/html; char ...

  8. AutoFac初探

    .net 4.0使用的DLL #region RegisterType注册 var builder = new ContainerBuilder(); builder.RegisterType< ...

  9. /boot磁盘空间不足,没盘扩展,只好删除旧内核了

    [xiejdm@localhost ~]$ uname -r -.el7.x86_64 [xiejdm@localhost ~]$ sudo rpm -qa | grep kernel kernel- ...

  10. [原创] Assistant editor 取消拖拽 binding 的 UI 元素

    1. press up-right button "show the utilities" 2. press "show the Connections inspecto ...