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. 几种常用的适配器--Adapter
  2. Android中自定义水平的ProgressBar
  3. [置顶] Android常用适配器控件
  4. Android踩坑日记:自定义水平和圆形ProgressBar样式
  5. Android UI设计——ListView控件与SimpleAdapter适配器(三)
  6. 使用android中drawline函数无法绘制水平线的解决办法
  7. Android studio :适配器控件
  8. Android适配器之-----SimpleCursorTreeAdapter
  9. Android的水平进度条和圆形进度条实例

随机推荐

  1. android本地化和国际化
  2. Android(安卓)studio异常记录
  3. Android: 获取当前线程状态
  4. Mac 进行 android 真机调试
  5. android给图片添加边框
  6. Android(安卓)DownloadManager的用法
  7. android UI 设计之 Tabs
  8. Android聊天背景图片变形解决方案
  9. Android(安卓)VSYNC详解
  10. Android常用库