改变ImageButton中的图像大小

时间:2018-03-19 19:15:15

标签: android image imageview imagebutton

我有一个ImageView和ImageButton。我使用位图来破坏我的源图像,并且它的大小已经改变,所以我使用这个代码为我的ImageView放大其中的图像:

LayoutParams params1 = new LayoutParams((int) (320.0f * scale), (int) (250.0f * scale));
ImgView.setLayoutParams(params1);

但这对ImageButton不起作用(它只放大按钮,而不是图像)。请帮助放大按钮内的图像。

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

android:scaleType =" fitCenter" 用于缩放Android图片。

<ImageButton
        android:id="@+id/button_topleft"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="0dp"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:padding="20dp"
        android:scaleType="fitCenter" />
相关问题