在代码中设置imagebutton的高度和宽度

imi*_*min 1 android

这是我的代码

ImageButton btnPlayVideo = (ImageButton) findViewById(R.id.btnPlayVideo);
btnPlayVideo.setBackgroundResource(R.drawable.play_icon_grey);
btnPlayVideo.setAdjustViewBounds(true);
btnPlayVideo.setMaxHeight(10);
btnPlayVideo.setMaxWidth(10);
Run Code Online (Sandbox Code Playgroud)

在我的xml中

<ImageButton
android:id="@+id/btnPlayVideo"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="@android:color/transparent"
android:layout_span="2" />
Run Code Online (Sandbox Code Playgroud)

但似乎setmaxheight和layout_height和宽度甚至不起作用.那么如何设置图像按钮的尺寸?

Vip*_*hah 5

您将需要使用android:scaleType它来调整大小以适应.

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher"
        android:scaleType="fitXY" />
Run Code Online (Sandbox Code Playgroud)

产生以下输出.

在此输入图像描述