1

我有一个画廊,其中包含一组在运行时下载的图像。

我按照这里的例子: http ://www.anddev.org/a_androidwidgetgallery__-_example-t332.html

但不是使用

i.setImageResource(this.myImageIds[position]);

我用了

i.setImageBitmap(bitmaps.get(position));

这不会填满屏幕的整个宽度,仅与此处指定的宽度一样多:

i.setLayoutParams(new Gallery.LayoutParams(150, 150)); 

当我增加这个数字时,项目会随之缩放,而不是在每个示例中显示更多图像。我什至尝试在将它们添加到集合之前缩放图像。不知道我错过了什么,或者其他例子可能在哪里。任何帮助都会很棒,谢谢。

4

2 回答 2

1

似乎您可以将布局的宽度设置为图像的实际大小。或通过某种逻辑计算比例因子。例如,当图像远离图库中心时,您可以减小图像的宽度。

public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(this.myContext);

        i.setImageResource(this.myImageIds[position]);
        /* Image should be scaled as width/height are set. */
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        /* Set the Width/Height of the ImageView. */
        int selectedPosition = ((Gallery) parent).getSelectedItemPosition();

        float scale = getScale(position - selected);

            int width = Math.round(IMAGE_WIDTH * scale);

            int height = Math.round(IMAGE_HEIGHT * scale);

            i.setLayoutParams(new Gallery.LayoutParams(width, height));

        return i;
    }
于 2011-04-15T08:48:28.233 回答
-1

在你的布局 xml 文件中,一定要设置 android:layout_width="fill_parent",像这样

<Gallery 
            android:id="@+id/gallery"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dip"
                        android:layout_gravity="center_horizontal|bottom"
                        android:padding="1dip"
                        android:background="#AA000000"
            />
于 2010-10-20T10:19:50.957 回答