到不了第二张,这不清楚啊,还没遇到过这样的情况,多贴点代码看看,怎么设置的,你要是不太依赖Gallery的话,我建议用viewpage,个人建议。

解决方案 »

  1.   

    Gallery没有用过,用下SurfaceView试试?做游戏大多数都是用SurfaceView,显示图片什么的妥妥的
      

  2.   


    viewPager我用了下,还不如gallery,用viewpaper拖动时,上下的拖动范围不能太大,否则会上下滚动。而不是左右动。
    先帮忙看下这个gallery的问题吧。
      

  3.   

    你的position是不是没有改变过?给份东西你参考下吧。感觉你改一下就可以完成上面的问题了
    package com.eoemobile.book.ex_widgetdemo;
     
    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.view.animation.AnimationUtils;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.Gallery;
    import android.widget.ImageSwitcher;
    import android.widget.ImageView;
    import android.widget.TextView;
    import android.widget.ViewSwitcher;
    import android.widget.Gallery.LayoutParams;public class ImageShowActivity  extends Activity implements
    AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory {
    CheckBox plain_cb;
    CheckBox serif_cb;
    CheckBox italic_cb;
    CheckBox bold_cb;     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);        setContentView(R.layout.image_show);
            setTitle("ImageShowActivity");        mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
            mSwitcher.setFactory(this);
            mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
                    android.R.anim.fade_in));
            mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
                    android.R.anim.fade_out));        Gallery g = (Gallery) findViewById(R.id.gallery);
            g.setAdapter(new ImageAdapter(this));
            g.setOnItemSelectedListener(this);
        }    public void onItemSelected(AdapterView parent, View v, int position, long id) {
            mSwitcher.setImageResource(mImageIds[position]);
        }    public void onNothingSelected(AdapterView parent) {
        }    public View makeView() {
            ImageView i = new ImageView(this);
            i.setBackgroundColor(0xFF000000);
            i.setScaleType(ImageView.ScaleType.FIT_CENTER);
            i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
            return i;
        }    private ImageSwitcher mSwitcher;    public class ImageAdapter extends BaseAdapter {
            public ImageAdapter(Context c) {
                mContext = c;
            }        public int getCount() {
                return mThumbIds.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(mContext);            i.setImageResource(mThumbIds[position]);
                i.setAdjustViewBounds(true);
                i.setLayoutParams(new Gallery.LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                i.setBackgroundResource(R.drawable.picture_frame);
                return i;
            }        private Context mContext;    }
     
    private Integer[] mThumbIds = {
                R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
                R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
                R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
                R.drawable.sample_thumb_6, R.drawable.sample_thumb_7};    private Integer[] mImageIds = {
                R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2,
                R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
                R.drawable.sample_6, R.drawable.sample_7}; 
    }XML:
           <ImageSwitcher 
           android:id="@+id/switcher"
                  android:layout_width="fill_parent" 
                  android:layout_height="fill_parent"
                  android:layout_alignParentTop="true"
                  android:layout_alignParentLeft="true" />
                  
           <Gallery android:id="@+id/gallery" 
           android:background="#55000000"
                  android:layout_width="fill_parent" 
                  android:layout_height="60dp"
                  android:layout_alignParentBottom="true"
                  android:layout_alignParentLeft="true"
                  android:gravity="center_vertical" 
                  android:spacing="16dp" />
      

  4.   

    package org.crazyit.gallery;import android.app.Activity;
    import android.content.res.TypedArray;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.animation.AnimationUtils;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageSwitcher;
    import android.widget.ImageView;
    import android.widget.Gallery.LayoutParams;
    import android.widget.ViewSwitcher.ViewFactory;/**
     * Description:
     * <br/>site: <a href="http://www.crazyit.org">crazyit.org</a> 
     * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee [email protected]
     * @version  1.0
     */
    public class GallaryTest extends Activity
    {
    int[] imageIds = new int[]
    {
    R.drawable.shuangzi, R.drawable.shuangyu,
    R.drawable.chunv, R.drawable.tiancheng, R.drawable.tianxie,
    R.drawable.sheshou, R.drawable.juxie, R.drawable.shuiping,
    R.drawable.shizi, R.drawable.baiyang, R.drawable.jinniu,
    R.drawable.mojie }; @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final Gallery gallery = (Gallery) findViewById(R.id.gallery);
    // 获取显示图片的ImageSwitcher对象
    final ImageSwitcher switcher = (ImageSwitcher) 
    findViewById(R.id.switcher);
    // 为ImageSwitcher对象设置ViewFactory对象
    switcher.setFactory(new ViewFactory()
    {
    @Override
    public View makeView()
    {
    ImageView imageView = new ImageView(GallaryTest.this);
    imageView.setBackgroundColor(0xff0000);
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    return imageView;
    }
    });
    // 设置图片更换的动画效果
    switcher.setInAnimation(AnimationUtils.loadAnimation(this,
    android.R.anim.fade_in));
    switcher.setOutAnimation(AnimationUtils.loadAnimation(this,
    android.R.anim.fade_out));
    // 创建一个BaseAdapter对象,该对象负责提供Gallery所显示的图片
    BaseAdapter adapter = new BaseAdapter()
    {
    @Override
    public int getCount()
    {
    return imageIds.length;
    }
    @Override
    public Object getItem(int position)
    {
    return position;
    }
    @Override
    public long getItemId(int position)
    {
    return position;
    } // 该方法的返回的View就是代表了每个列表项
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
    // 创建一个ImageView
    ImageView imageView = new ImageView(GallaryTest.this);
    imageView
    .setImageResource(imageIds[position % imageIds.length]);
    // 设置ImageView的缩放类型
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setLayoutParams(new Gallery.LayoutParams(75, 100));
    TypedArray typedArray = obtainStyledAttributes(
    R.styleable.Gallery);
    imageView.setBackgroundResource(typedArray.getResourceId(
    R.styleable.Gallery_android_galleryItemBackground, 0));
    return imageView;
    }
    };
    gallery.setAdapter(adapter);
    gallery.setOnItemSelectedListener(new OnItemSelectedListener()
    {
    // 当Gallery选中项发生改变时触发该方法
    @Override
    public void onItemSelected(AdapterView<?> parent, View view,
    int position, long id)
    {
    switcher.setImageResource(imageIds[position % imageIds.length]);
    } @Override
    public void onNothingSelected(AdapterView<?> parent)
    {
    }
    });
    }
    }以上是一份例子,楼主自己对照,图片需要卤煮自己定义,
    一下是布局文件
    <?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">
    <!-- 定义一个ImageSwitcher组件 -->
    <ImageSwitcher android:id="@+id/switcher"
    android:layout_width="320dp"
    android:layout_height="320dp"
    />
    <!-- 定义一个Gallery组件 -->
    <Gallery android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dp" 
    android:unselectedAlpha="0.6"
    android:spacing="3pt"
    />
    </LinearLayout>
    希望能帮助到你
      

  5.   

    感谢上面各位兄弟回复,不过自己挖的坑自己埋。原因是使用了Image-loader,后来我把Image-loader的内存、硬盘缓存去掉了,好了。。缺点是让他每次都从网上去取吧。话说用框架出现的问题还真是难找啊options = new DisplayImageOptions.Builder()
                    .showImageOnLoading(
                            GetItemId.getDrawableResIDByName(context, "suma_default_poster"))
                    .showImageForEmptyUri(
                            GetItemId.getDrawableResIDByName(context, "suma_default_poster"))
                    .showImageOnFail(GetItemId.getDrawableResIDByName(context, "suma_default_poster"))
    //                .cacheInMemory(true)
    //                .cacheOnDisc(true)