I am trying to set padding of an ImageView. My code is below
private void createEpisodeView() {
float scale = this.getResources().getDisplayMetrics().density;
int padding = (int) (PADDING * scale + 0.5f);
rlItemsRoot = (LinearLayout) findViewById(R.id.rl_items_root);
for (int i = 0; i < GameLevels.TOTAL_EPISODES; i++) {
ImageView iv = new ImageView(this);
iv.setPadding(padding, padding, padding, padding);
iv.setBackgroundResource(R.drawable.icon_small);
rlItemsRoot.addView(iv);
}
}
But it has no effect. but when I set this in XML it looks fine.
A you noticed yourself you are using
This will set the Background for the ImageView. The Background Image will fill the whole view because it is behind all the content in the View.
Use
instead.