在画廊更改边框样式 [英] Change border style in Gallery

查看:203
本文介绍了在画廊更改边框样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以教程。正如你可以看到在这个形象,标准的灰色边框被应用到所有在画廊的元素。我想删除这个比较难看的边界,或者,实际上,使其成为1像素的边界,而不是(或只是这样的图像可以从彼此区分)。 我试图消除这一行:

I am taking this tutorial. As you can see on this image, the standard grey border is applied to all elements in the gallery. I would like to remove this rather ugly border, or, actually, make it a 1 px border instead (or just so the images can be distinguished from each other). I tried removing this line:

imgView.setBackgroundResource(GalItemBg);

这消除了边界,但随后的影像相互重叠,它仍然不是很pretty的。

That removes the border, but then the images overlap each other and it's still not very pretty.

那么,如何才能更改边界?而且我怎么画廊元素不互相重叠?

So, how do I change the border? And how do I get the gallery elements to not overlap each other?

推荐答案

我敢肯定,你已经发现了这个问题的答案,但有没有贴出来,这里有一个了!

I'm sure you've already discovered an answer for this problem, but as there's none posted, here's one now!

您可以将您的每个 imgView 对象的 RelativeLayout的里面有一个黑色的背景和1填充。然后返回 RelativeLayout的对象包含的ImageView ,而不是返回ImageView的本身。

You can place each of your imgView objects inside of a RelativeLayout with a black background and a 1 padding. Then return the RelativeLayout object containing the ImageView instead of returning the ImageView itself.

public View getView(int position, View convertView, ViewGroup parent)
{
    ImageView imgView = new ImageView(m_Context);
    // do stuff initializing your imgView as before
    RelativeLayout borderImg = new RelativeLayout(m_Context);
    borderImg.setPadding(1,1,1,1);
    borderImg.setBackgroundColor(0xff000000);
    borderImg.addView(imgView);
    return borderImg;
}

最后,它是非常容易使用库法 setSpacing(INT像素)图库图像之间的间隔$ C>把之间的每个图库对象的空间。你不会得到他们周围的黑色边框,但图库背景将是可见的,并在他们身后。

Finally, it is much easier to enforce a spacing between your Gallery images by using the Gallery method setSpacing(int pixels) to put a space between each Gallery object. You won't get the black border around them, but the Gallery background will be visible between and behind them.

这篇关于在画廊更改边框样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆