you are trying to change the image of a Button
which doesn't have the properties of Button
according to this setImageViewResource
is equivilant to ImageView
properties so Instead of having a button I suggest you change it either to ImageButton
or to ImageView
that is clickable.
so maybe your XML will look like this:
<ImageButton
android:id="@+id/button"
android:paddingRight="30dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/vai" />
Update
the reason is that android:background
is different than android:src
it doesn't resize the photo it actually make the image as size of the photo (setImageViewResource is same as src) .. so you have either to resize the photo from the beginning or try to add this attribute to your ImageButton
android:scaleType="fitXY"
but I am not sure it will work, haven't tried it.
hope this works for you. try it out and give me a feedback.