Q:

set imagebutton height and width in code

this is my code
ImageButton btnPlayVideo = (ImageButton) findViewById(R.id.btnPlayVideo);
btnPlayVideo.setBackgroundResource(R.drawable.play_icon_grey);
btnPlayVideo.setAdjustViewBounds(true);
btnPlayVideo.setMaxHeight(10);
btnPlayVideo.setMaxWidth(10);

and in my xml
<ImageButton
android:id="@+id/btnPlayVideo"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="@android:color/transparent"
android:layout_span="2" />

but it seems the setmaxheight and layout_height and width doesn't even work. so how do i set the imagebutton's dimension?

A:

You will need to use android:scaleType to have it resize to fit.
<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher"
        android:scaleType="fitXY" />

Which produces following output.

A:

You can do it from code via
android.view.ViewGroup.LayoutParams params = btnPlayVideo.getLayoutParams();
params.height = myHeight;
params.width = myWidth;
btnPlayVideo.setLayoutParams(params);

, but probably your problem lays not in the code, but in layout - I see you are using android:layout_span="2" - does that mean btnPlayVideo is in TableLayout? If so, you must regulate this TableLayout's dimensions, because its children will always have fill_parent width and heights.

