I have four ImageViews
in a layout. I set the maximum width for each one of them by setMaxWidth
function. The problem is that they keep a small distance between them and I don't want that. If I don't stipulate the maximum width, these gaps disappear, but the ImageViews
sizes are inappropriate (bigger than it should be).
The main code is:
musicSubmenuButton = new ImageView(context);
musicSubmenuButton.setId(id++);
musicSubmenuButton.setImageResource(R.drawable.bt_musicas_on);
musicSubmenuButton.setMaxWidth(buttonSize);
musicSubmenuButton.setAdjustViewBounds(true);
photosSubmenuButton = new ImageView(context);
photosSubmenuButton.setId(id++);
photosSubmenuButton.setImageResource(R.drawable.bt_fotos_off);
photosSubmenuButton.setMaxWidth(buttonSize);
photosSubmenuButton.setAdjustViewBounds(true);
agendaSubmenuButton = new ImageView(context);
agendaSubmenuButton.setId(id++);
agendaSubmenuButton.setImageResource(R.drawable.bt_agenda_off);
agendaSubmenuButton.setMaxWidth(buttonSize);
agendaSubmenuButton.setAdjustViewBounds(true);
infoSubmenuButton = new ImageView(context);
infoSubmenuButton.setId(id++);
infoSubmenuButton.setImageResource(R.drawable.bt_info_off);
infoSubmenuButton.setMaxWidth(buttonSize);
infoSubmenuBut开发者_如何学Pythonton.setAdjustViewBounds(true);
The size I wanted, but without the gaps (obtained using the above code):
The ImageViews without the gaps, but in the original resolution (obtained using the above code, but commenting the setAdjustViewBounds
calls):
Does anybody know why these gaps appear and/or a workaround to get rid of these gaps and keep my desired size?
Instead of setting max width, set layout_width on them to fill_parent. Then they will space out evenly.
精彩评论