package com.zte.android.lesstion;     import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.AdapterView;import android.widget.Gallery;import android.widget.Toast;/** * @author rychenga *  * 水平方向上显示一组图片,以便于浏览 */public class Activity_012_Gallery extends Activity{private Gallery gallery ;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_012_gallery_layout);//init gallerygallery = (Gallery)findViewById(R.id.l012_gallery1);//设置适配器(datasource)Activity_012_ImageAdapter adapter = new Activity_012_ImageAdapter(Activity_012_Gallery.this);gallery.setAdapter(adapter);//显示被选中部分所处的位置,显示信息持续2秒gallery.setOnItemSelectedListener(new OnItemSelectedListener() {//覆盖2个默认方法public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {// TODO Auto-generated method stubToast.makeText(Activity_012_Gallery.this,"第"+position+"张", 2).show();}public void onNothingSelected(AdapterView<?> arg0) {// TODO Auto-generated method stub}});}}  


<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <Gallery        android:id="@+id/l012_gallery1"        android:layout_width="match_parent"        android:layout_height="300dp"/></LinearLayout>

更多相关文章

  1. Android(安卓)BottomNavigationView的使用
  2. android收发短信
  3. android UI组件
  4. android clipPath切割画布
  5. Android(安卓)WiFi管理(WIFI_SERVICE)
  6. Android搜索框自动提示文本框——(单一提示)
  7. Android(安卓)自定义SeekBar显示进度百分比
  8. android中sqlite的使用
  9. Android在屏幕任意位置显示对话框

随机推荐

  1. 在eclipse的android工程里引用android sd
  2. Android(安卓)上Camera分析
  3. 使用html,javascript,css,phonegap创建开
  4. android系统定制从听说到入门二
  5. Android面试基础
  6. android基础知识03——事件处理01:主要事
  7. Android架构分析之Android消息处理机制(一
  8. android 跑马灯
  9. android VelocityTracker简单用法
  10. Android(安卓)SDK 1.6下载地址