如何在android中的图库中设置图像布局参数
我想在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.
您可能会考虑在布局中使用
dp
。这将涉及一些缩放,但它将使您的应用程序在设备上兼容。您可以通过点击和试用为
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.You can choose an appropriate value for
DP_VALUE
through hit and trial.