Android : How can I change ImageButton size from xml in java

on Friday, April 3, 2015


I have a some problem in my android project.


This is my xml code for ImageButton with fixed width and height.



<ImageButton
android:layout_width="120dp"
android:layout_height="120dp"
android:id="@+id/ball1"
android:background="@drawable/ball"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />


And here i called in java that ImageButton:



ImageButton ball1 = (ImageButton) findViewById(R.id.ball1);


My question is, what I need to do, to subtract my layout_width and layout_height by 10dp in java code?


Something like this:



int width = ball1.getWidth();
int height = ball1.getHeight();
width = width - 10dp;
height = height - 10dp;


So how can I subtract Height and Width by 10dp?


0 comments:

Post a Comment