Gallery 的 Demo

来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 11:55 点击:
Gallery 的 Demo 
gallery.xml 
 
代码  
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
 
    <!-- 
        Gallery - 缩略图浏览器控件 
            spacing - 缩略图列表中各个缩略图之间的间距 
    --> 
    <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" 
        android:layout_height="wrap_content" android:spacing="20px" /> 
 
</LinearLayout> 
 
 
_Gallery.java 
 
代码  
package com.webabcd.view; 
 
import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.BaseAdapter; 
import android.widget.Gallery; 
import android.widget.ImageView; 
import android.widget.Toast; 
import android.widget.Gallery.LayoutParams; 
 
public class _Gallery extends Activity { 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        // TODO Auto-generated method stub 
        super.onCreate(savedInstanceState); 
        this.setContentView(R.layout.gallery); 
 
        setTitle("Gallery"); 
 
        Gallery gallery = (Gallery) findViewById(R.id.gallery); 
        // 为缩略图浏览器指定一个适配器 
        gallery.setAdapter(new ImageAdapter(this)); 
        // 响应 在缩略图列表上选中某个缩略图后的 事件 
        gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
            @Override 
            public void onItemSelected(AdapterView<?> parent, View v, 
                    int position, long id) { 
                Toast.makeText(_Gallery.this, String.valueOf(position), Toast.LENGTH_SHORT).show(); 
            } 
 
            @Override 
            public void onNothingSelected(AdapterView<?> arg0) { 
 
            } 
        }); 
    } 
 
    // 继承 BaseAdapter 用以实现自定义的图片适配器 
    public class ImageAdapter extends BaseAdapter { 
 
        private Context mContext; 
 
       

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Java编程语言的八大优点
      • JVM对象生命周期详细介绍
      • Java平台上的CRM系统
      • Java 算数测试小程序
      • Command(命令模式)
      • Java 一个简单的画图程序
      • Java环境 使用Resin在NT环境下配置JSP环境
      • Java 日历的小程序
      • Java 统计代码的小工具
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1