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;
}
}


}

更多相关文章

  1. Android 文件存储 和 权限管理
  2. 二十四、Android文件的读写
  3. Android初级教程理论知识(第二章布局&读写文件)
  4. Android 文件读写最全解析
  5. android学习之textView布局文件
  6. AndroidManifest.xml文件详解(data)

随机推荐

  1. android怎样实现关闭系统自动旋转屏幕时
  2. 教你如何更改android应用的包名
  3. Android(安卓)Studio调错误方法
  4. Android(安卓)使用level-list改变对应的
  5. EditText失去焦点时收起软键盘
  6. Android(安卓)IPC 通讯机制源码分析 二
  7. Android系统启动流程(源码分析)
  8. Android(安卓)SDK 与API版本对应关系
  9. 全新 Android(安卓)注入器:Dagger 2(一)
  10. android system setup and building (2)