Gallery-Dome图片滑动效果



amxl

<?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" />
</RelativeLayout>



Activity cs

 [Activity(Label = "My Activity")]
    public class layout1 : Activity
    {
        private static int[] images = {Resource.Drawable.baos,
                                       Resource.Drawable.caoc,
                                       Resource.Drawable.chenyj,
                                       Resource.Drawable.chenyy,
                                       Resource.Drawable.gouj
                                      };
        Gallery gallery;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Create your application here            
            SetContentView(Resource.Layout.layout1);
            Title="Gallery的效果";           
            gallery =FindViewById<Gallery>(Resource.Id.gallery1);
            ImageAdapter gallimage = new ImageAdapter(this, images);
            gallery.Adapter=gallimage;           
            gallery.SetSelection(images.Length / 2);
            gallery.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs args)
            {
                Toast.MakeText(this, args.Position.ToString(), ToastLength.Short).Show();
            };

        }
    }


重写 BaseAdapter类

 public class ImageAdapter:BaseAdapter {
        private Context context;
        private int[] images;

        public ImageAdapter(Context context, int[] images)
        {
            this.context = context;
            this.images = images;
        }
        public override int Count
        {
            get {
                return images.Length;
            }
        }

        public override long GetItemId(int position)
        {
            return 0;
        }
        public override Java.Lang.Object GetItem(int position)
        {
            return null;
        }

        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            ImageView iv = new ImageView(context);
            //设置具体要显示的图片
            iv.SetImageResource(images[position % images.Length]);
            //设置ImageView的高度和宽度           
           Gallery.LayoutParams paramsatturt = new Gallery.LayoutParams(Gallery.LayoutParams.FillParent,Gallery.LayoutParams.FillParent);
           iv.LayoutParameters=paramsatturt; 
            //设置缩放
            iv.SetScaleType(ImageView.ScaleType.FitXy);            
            iv.SetAdjustViewBounds(true);
           return iv;
        }
    }

源码实例 http://download.csdn.net/detail/hcf_force/7128141





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值