Change border style in Gallery

心不动则不痛 提交于 2019-12-05 08:12:56

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!