欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android Gallery组件实现的iPhone图片滑动效果实例

程序员文章站 2022-05-27 10:21:54
实现的效果图,可左右滑动: 一、先在将gallery标签放入: 复制代码 代码如下:

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

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;
    }
}