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);
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!
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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With