发布于 2016-04-15 12:47:26 | 261 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了android Gallery组件实现的iPhone图片滑动效果实例,即相册内的图片实现可左右滑动的效果,需要的朋友可以参考下

实现的效果图,可左右滑动:

一、先在将Gallery标签放入:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView  

    android:layout_width="fill_parent" 

    android:layout_height="wrap_content" 

    android:text="@string/hello"

    />

<Gallery

    android:id="@+id/gallery"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

/>

</LinearLayout>

二、Gallery 需要用Adapter来填充,先从BaseAdapter中派生一个ImageAdapter出来
public class ImageAdapter extends BaseAdapter

{

    private Context context;

    private int[] MyImageIDs =

    { R.drawable.icon, R.drawable.carlogo_52design_09,

            R.drawable.carlogo_52design_13, R.drawable.carlogo_52design_19,

            R.drawable.carlogo_52design_24, R.drawable.carlogo_52design_27,

            R.drawable.carlogo_52design_29, R.drawable.carlogo_52design_31,

            R.drawable.carlogo_52design_34, R.drawable.carlogo_52design_36 };

    public ImageAdapter(Context context)

    {

        // TODO Auto-generated constructor stub

        this.context = context;

    }

    @Override

    public int getCount()

    {

        // TODO Auto-generated method stub

        return MyImageIDs.length;

    }

    @Override

    public Object getItem(int arg0)

    {

        // TODO Auto-generated method stub

        return arg0;

    }

    @Override

    public long getItemId(int position)

    {

        // TODO Auto-generated method stub

        return position;

    }

    @Override

    public View getView(int position, View convertView, ViewGroup parent)

    {

        // TODO Auto-generated method stub

        ImageView i = new ImageView(this.context);

        i.setImageResource(this.MyImageIDs[position]);

        i.setScaleType(ImageView.ScaleType.FIT_XY);

        i.setLayoutParams(new Gallery.LayoutParams(120, 120));

        return i;

    }

}



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务