是否设置可点击或可选中呢?  setClickable  setSelectable

解决方案 »

  1.   

    gallery早就被android抛弃了,还是用HorizontalScrollView吧
      

  2.   

    HorizontalScrollView一次加载太多view和单击事件,会死机的。
      

  3.   

    推荐你使用imageLoader库来加载图片
      

  4.   

    知道原因了,就是
    public class CGallery extends Gallery
    {
        private Camera mCamera;
        private int mWidth;
        private int mPaddingLeft;
        private boolean flag;
        private static int firstChildWidth;
        private static int firstChildPaddingLeft;    public CGallery(Context context)
        {
            super(context);
            mCamera = new Camera();
            this.setStaticTransformationsEnabled(true);
        }
        public CGallery(Context context, AttributeSet attrs) {
            super(context, attrs);
            mCamera = new Camera();
            //setAttributesValue(context, attrs);
            this.setStaticTransformationsEnabled(true);
        }
        public CGallery(Context context, AttributeSet attrs, int defStyle)
        {
            super(context, attrs, defStyle);
            mCamera = new Camera();
            //setAttributesValue(context, attrs);
            this.setStaticTransformationsEnabled(true);
        }
        private void setAttributesValue(Context context, AttributeSet attrs)
        {
            TypedArray typedArray = context.obtainStyledAttributes(attrs, new int[] { attr.paddingLeft });
            mPaddingLeft = typedArray.getDimensionPixelSize(0, 0);
            typedArray.recycle();
        }    protected boolean getChildStaticTransformation(View child, Transformation t)
        {
            t.clear();
            t.setTransformationType(Transformation.TYPE_MATRIX);
            mCamera.save();
            final Matrix imageMatrix = t.getMatrix();
            final int imageHeight = child.getLayoutParams().height;
            final int imageWidth = child.getLayoutParams().width;
            if (flag)
            {
                firstChildWidth = getChildAt(0).getWidth();
                firstChildPaddingLeft = getChildAt(0).getPaddingLeft();
                flag = false;
            }
            mCamera.translate(firstChildWidth / 2 + firstChildPaddingLeft + mPaddingLeft - mWidth / 2, 0f, 0f);
            mCamera.getMatrix(imageMatrix);
            mCamera.restore();
            return true;
        }
        protected void onSizeChanged(int w, int h, int oldw, int oldh)
        {
            if (!flag)
            {
                mWidth = w * 2;
                getLayoutParams().width = mWidth;
                flag = true;
            }
            super.onSizeChanged(w, h, oldw, oldh);
        }
    }
    上面把gallery的item子项左边对齐,但是单击区域却不对称了,搞成右边对齐了。怎么办呢?