1.介绍

就是Gallery组件,可滑动图片,产生图片的滑动效果!


2.效果图

3.XML文件

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

4.Java代码

 package wei.ye.g1;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 Huadong extends Activity {    private static int[] images = { R.drawable.baos, R.drawable.caoc,            R.drawable.chenyj, R.drawable.chenyy, R.drawable.gouj,            R.drawable.guany, R.drawable.hanx, R.drawable.lp, R.drawable.liub,            R.drawable.qinq, R.drawable.tiemz, R.drawable.wus,            R.drawable.xiangy, R.drawable.yuef, R.drawable.zhaoky,            R.drawable.zhugl, R.drawable.xis, R.drawable.yingz };    Gallery gallery;    @Override    protected void onCreate(Bundle savedInstanceState) {        // TODO Auto-generated method stub        super.onCreate(savedInstanceState);        setContentView(R.layout.huadong);        setTitle("只用了Gallery的效果");        gallery = (Gallery) findViewById(R.id.gallery1);        gallery.setAdapter(new ImageAdapter(this));        gallery.setSelection(images.length / 2);    }    private class ImageAdapter extends BaseAdapter {        private Context context;        public ImageAdapter(Context context) {            this.context = context;        }        // 可以return images.lenght(),在这里返回Integer.MAX_VALUE        // 是为了使图片循环显示        public int getCount() {            return Integer.MAX_VALUE;        }        public Object getItem(int position) {            return null;        }        public long getItemId(int position) {            return 0;        }        public View getView(int position, View convertView, ViewGroup parent) {            ImageView iv = new ImageView(context);            //设置具体要显示的图片            iv.setImageResource(images[position % images.length]);            //设置ImageView的高度和宽度            iv.setLayoutParams(new Gallery.LayoutParams(                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));            iv.setAdjustViewBounds(true);            return iv;        }    }}

更多相关文章

  1. Android数字跑动效果NumberRunView 类似支付宝数字跑动
  2. Android开发学习:ImageView的scaletype属性
  3. Android中RecyclerView左右侧滑
  4. Android之背景图片设置为重复而不是默认的拉伸
  5. 调整recovery界面菜单字体大小
  6. android嵌套滑动- Material Design
  7. android 拍照+从手机相册选择返回图片到imagview
  8. [Android] ImageView.ScaleType设置图解
  9. Android(安卓)利用shape自定义进度条样式

随机推荐

  1. Android之布局属性归纳
  2. Android精简代号
  3. Android应用开发——系统自带样式Android
  4. Android实现TextView跑马灯效果
  5. Android之布局属性归纳
  6. Android(安卓)相对布局
  7. Android之布局属性归纳
  8. android 布局问题总结
  9. 系统自带样式Android:theme
  10. android选项卡