Gallery

来源:互联网 发布:意大利语发音规则 知乎 编辑:程序博客网 时间:2024/05/11 04:47

<ImageSwitcher android:id="@+id/switcher"
     android:layout_width="fill_parent"
       android:layout_height="wrap_content"
        />
     
    <Gallery android:id="@+id/gallery"
        android:background="#55000000"
        android:layout_width="fill_parent"
  android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"     
        android:gravity="center_vertical"
        android:spacing="16dp" />

 

Gallery gallery=(Gallery)findViewById(R.id.gallery);
    gallery.setAdapter(new ImageAdapter(this));

 


public class ImageAdapter extends BaseAdapter
{
    private Context myContext;
    private int [] myImageIds=
    {
            android.R.drawable.btn_minus,
            android.R.drawable.btn_radio,
            android.R.drawable.ic_lock_idle_low_battery,
            android.R.drawable.ic_menu_camera
    };
    public ImageAdapter(Context c){this.myContext=c;}
    public int getCount(){return this.myImageIds.length;}
    public Object getItem(int position){
        return position;
    }
    public long getItemId(int position){
        return position;
    }
    public View getView(int position,View convertView,ViewGroup parent)
    {
        ImageView i=new ImageView(this.myContext);
        i.setScaleType(ImageView.ScaleType.FIT_XY);
       
        i.setLayoutParams(new Gallery.LayoutParams(120,120));
        return i;
    }
    public float getScale(boolean focused,int offset)
    {
        return Math.max(0,1.0f/(float)Math.pow(2,Math.abs(offset)));
    }
}

原创粉丝点击