如何在android中的图库中设置图像布局参数

发布于 2024-11-18 17:44:20 字数 686 浏览 3 评论 0原文

我想在android中使用画廊,所以在适配器类中我设置了

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {

        ImageView iView = new ImageView(ctx);
        iView.setImageResource(pics[arg0]);
        iView.setScaleType(ImageView.ScaleType.FIT_XY);
        //iView.setLayoutParams(new Gallery.LayoutParams(150, 150));
        iView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        return iView;
    }

所以它重叠了我的所有图像,它不能一一正确显示。

但如果我设置

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

,它不会重叠图像,但图像大小会增加.. 那么如果我想包装图像高度宽度的内容我必须做什么

谢谢

I want to use gallery in android so in adapter class I have set

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {

        ImageView iView = new ImageView(ctx);
        iView.setImageResource(pics[arg0]);
        iView.setScaleType(ImageView.ScaleType.FIT_XY);
        //iView.setLayoutParams(new Gallery.LayoutParams(150, 150));
        iView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        return iView;
    }

So it overlap all my image, it does not show properly one by one.

but if I set

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

then it does not overlap image but image size will increase..
So What I have to do if I want to wrap content of image height width

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

查看画廊文档: http://developer.android.com/reference/android/小部件/Gallery.html
您可以在图库对象上使用“setSpacing”方法来强制图像不重叠。

Look at gallery doc: http://developer.android.com/reference/android/widget/Gallery.html
You can use "setSpacing" method on gallery object to force images not to overlap.

风蛊 2024-11-25 17:44:20

您可能会考虑在布局中使用dp。这将涉及一些缩放,但它将使您的应用程序在设备上兼容。

final float scale = getResources().getDisplayMetrics().density;
int pixels = (int) ( DP_VALUE * scale + 0.5f);
iView.setLayoutParams(new Gallery.LayoutParams(pixels, pixels));

您可以通过点击和试用为 DP_VALUE 选择合适的值。

You could probably look at using dp in your layout. This would involve some scaling but it would make you app compatible over devices.

final float scale = getResources().getDisplayMetrics().density;
int pixels = (int) ( DP_VALUE * scale + 0.5f);
iView.setLayoutParams(new Gallery.LayoutParams(pixels, pixels));

You can choose an appropriate value for DP_VALUE through hit and trial.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文