Android之gallery
来源:互联网 发布:如何选择电视机 知乎 编辑:程序博客网 时间:2024/06/04 23:33
运行结果图
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Gallery android:id="@+id/myGallery" android:layout_width="fill_parent" android:layout_height="fill_parent" android:spacing="2px"/></LinearLayout>
ImageAdapter.java
package xyq.demo;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageView;public class ImageAdapter extends BaseAdapter{private Context context;private int[] MyImageIds = {R.drawable.image1,R.drawable.image2,R.drawable.image3,R.drawable.image4,R.drawable.image5,R.drawable.image6};public ImageAdapter(Context context){this.context=context;}@Overridepublic int getCount() {return MyImageIds.length;}@Overridepublic Object getItem(int position) {return position;}@Overridepublic long getItemId(int id) {return id;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ImageView imageView = new ImageView(this.context);imageView.setImageResource(this.MyImageIds[position]);imageView.setLayoutParams(new Gallery.LayoutParams(320, 480));imageView.setScaleType(ImageView.ScaleType.FIT_XY);return imageView;}}TestActivity.java
package xyq.demo;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.Gallery;import android.widget.Toast;public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Gallery myGallery = (Gallery)findViewById(R.id.myGallery); myGallery.setAdapter(new ImageAdapter(this)); //myGallery.setBackgroundResource(R.drawable.image0); myGallery.setOnItemClickListener(new GalleryItemListener()); } class GalleryItemListener implements OnItemClickListener { @Overridepublic void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) {// TODO Auto-generated method stubToast.makeText(TestActivity.this, "你选择了" + (position + 1) + " 号图片", Toast.LENGTH_SHORT).show();} } }代码地址
- Android之Gallery
- Android之gallery
- android控件之gallery
- Android之浅谈Gallery
- Android之Gallery
- android之Gallery
- Android控件之Gallery
- Android之Gallery
- android:布局之Gallery
- Android控件之Gallery
- Android控件之Gallery
- Android之Gallery控件使用
- Android 控件使用之 Gallery
- Android控件开发之Gallery
- android之Gallery默认实现
- android之3D Gallery
- Android学习笔记之Gallery
- Android控件之Gallery探究
- 使用rsync完成Linux服务器间同步目录
- 不可不知道国内虚拟化厂商
- .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
- 关于APACHE 无权限访问的问题 403 解决方案
- Ideal education
- Android之gallery
- cygwin完整版下载地址
- CSMA/CD CSMA/CA
- 山寨开机选择四大系统-----------RadioGroup 、RadioButton单选按钮
- 魔术师发牌问题C++实现
- HTTP服务七层架构技术探讨
- 程序员怎样读书
- scrollView的几个属性contentSize contentOffset contentInset
- Linuc--C--getchar