0

I've created a refresh animation to my icon. But after setting the imageResource to the button the layout is broken.

enter image description here

Before creating my animation and setting the imageResource the button looked like this with margin/padding:

enter image description here

I've set the imageResource with following code:

ImageView reloadButton = (ImageView) menu.findItem(R.id.menu_reloaditem).getActionView();

reloadButton.setImageResource(R.drawable.ic_menu_reloadentry);

Unable to track reason for this issue. Any help would be really valuable.

Jose Rodriguez
  • 9,753
  • 13
  • 36
  • 52
ItsOdi1
  • 219
  • 3
  • 22
  • Check drawable dpi image... If you have all drawable images resolution for both – Felipe A. Jan 27 '17 at 13:09
  • Look at your xml code. the "plus" button is likely a part of your xml code. Since you added the reloadbutton programatically maybe that´s the issue? i.e set a margin and padding here in your java code. – Tacolibre Jan 27 '17 at 13:09
  • The are exactly the same. The plus is just set from xml and the reload button in the programm – ItsOdi1 Jan 27 '17 at 13:10
  • Look at this post, http://stackoverflow.com/questions/3416087/how-to-set-margin-of-imageview-using-code-not-xml maybe this will help. – Tacolibre Jan 27 '17 at 13:12
  • @Tacolibre I've set the reload icon at the menu item in xml too but the animation on this is removing this icon so you need to set it new like I did. But it looks like that padding/margin is missing. The problem is I don't know the exact margins from the standard layout – ItsOdi1 Jan 27 '17 at 13:12

1 Answers1

0

check whether icon images are having same size. resolution

  • They are the same resolution ;) before creating an animation I've set the same icon as a normal icon to the bar and I looks brilliant with padding/margin like the plus icon – ItsOdi1 Jan 27 '17 at 13:08
  • But when you create an animation you need to set a resource manually in the program and thats the problem. The xml know the margin/padding (just an idea) – ItsOdi1 Jan 27 '17 at 13:09
  • you are using ImageView instead of ImageButton – Dinesh Hebbar Jan 27 '17 at 13:09
  • create a layout for the menu icons, set padding and margin for the layout instead of button and try. – Dinesh Hebbar Jan 27 '17 at 13:10