3.15 MonoForAndroid用户人机界面--如IPHONE拖动相片特效 Gallery画廊

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/white"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/myTextView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/Hello"
        android:gravity="center_vertical|center_horizontal" />
    <Gallery
        android:id="@+id/myGallery1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom" />
</LinearLayout>

MainActivity.cs

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
//
using Android.Graphics;
namespace Ex03_15
{
    [Activity(Label = "Ex03_15", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        //int count = 1;
        private TextView mTextView01;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            mTextView01 = (TextView) FindViewById(Resource.Id.myTextView01); 
            mTextView01.SetText(Resource.String.str_txt1,TextView.BufferType.Normal );
            mTextView01.SetTextColor(Color.Blue);
            ((Gallery)FindViewById(Resource.Id.myGallery1)).Adapter = new ImageAdapter(this); 
        }
       public class ImageAdapter : BaseAdapter 
        { 
            /* 类成员 myContext为Context父类 */ 
            private Context myContext; 
            /*使用android.R.drawable里的图片作为图库来源,类型为整数数组*/
            private int[] myImageIds = { 
                                           Resource.Drawable.Icon ,
                                           Resource.Drawable.Icon1,
                                           Resource.Drawable.Icon2 ,
                                           Resource.Drawable.Icon3 ,
                                           Resource.Drawable.Icon4 ,
                                           Resource.Drawable.Icon5 ,
                                           Resource.Drawable.Icon6,
                                           Resource.Drawable.Icon7
                                           }; 
            /* 建构子只有一个参数,即要储存的Context */ 
            public ImageAdapter(Context c) 
            { 
                this.myContext = c; 
            } 
            /* 回传所有已定义的图片总数量 */
            public override int Count
            {
                get
                {
                    return this.myImageIds.Length;
                }
            }
            /* 利用getItem方法,取得目前容器中影像的数组ID */ 
            public override Java.Lang.Object GetItem(int position) 
            { 
                return position; 
            }
            public override long GetItemId(int position) 
            { 
                return position;
            } 
            /* 取得目前欲显示的影像View,传入数组ID值使之读取与成像 */
            public override View GetView(int position, View convertView, ViewGroup parent) 
            { 
                /* 建立一个ImageView对象 */ 
                ImageView i = new ImageView(this.myContext); 
                //i.setImageResource(this.myImageIds[position]); 
                //i.setScaleType(ImageView.ScaleType.FIT_XY); 
                ///* 设定这个ImageView对象的宽高,单位为dip */ 
                //i.setLayoutParams(new Gallery.LayoutParams(120, 120)); 
                i.SetImageResource(this.myImageIds[position]);
                i.SetScaleType(ImageView.ScaleType.FitXy);
                i.LayoutParameters=new Gallery.LayoutParams(120,120);
                return i;
            } 
            /*依据距离中央的位移量 利用getScale回传views的大小(0.0f to 1.0f)*/ 
            public float GetScale(bool  focused, int offset) 
            { 
                /* Formula: 1 / (2 ^ offset) */ 
                return Math.Max(0,1.0f/(float)Math.Pow(2,Math.Abs(offset))); 
            } 
        }
    }
 
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值