Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android Gallery組件實現的iPhone圖片滑動效果實例

android Gallery組件實現的iPhone圖片滑動效果實例

編輯:關於Android編程

實現的效果圖,可左右滑動:

一、先在將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;
    }
}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved