Java Can';t重新缩放可缩进按钮

Java Can';t重新缩放可缩进按钮,java,android,Java,Android,我正在尝试缩小一个可在按钮中使用的绘图。现在,我的按钮中没有显示任何内容: 左边应该有一个抽屉。 这里有什么问题?我所做的和我在这里看到的不同答案中看到的完全一样 XML: 也许这个选项会有所帮助 <Button android:id="@+id/fnbButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@d

我正在尝试缩小一个可在
按钮中使用的绘图。现在,我的按钮中没有显示任何内容:

左边应该有一个抽屉。 这里有什么问题?我所做的和我在这里看到的不同答案中看到的完全一样

XML:


也许这个选项会有所帮助

<Button
    android:id="@+id/fnbButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_button_blue"
    android:padding="5dp"
    android:text="@string/fnb_button"
    android:textAllCaps="false"
    android:textColor="@color/white"
    app:layout_constraintBaseline_toBaselineOf="@id/otherButton"
    app:layout_constraintEnd_toEndOf="parent" />
试试这个

   private void useScaledDrawableLeft(Button buttonView, float scale, @DrawableRes int imageResource) {
        Resources res = getResources();
        BitmapDrawable bd = (BitmapDrawable) res.getDrawable(imageResource);
        Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(),
                (int) (bd.getIntrinsicHeight() * scale),
                (int) (bd.getIntrinsicWidth() * scale),
                false);

        BitmapDrawable scaleDrawable = new BitmapDrawable(b);
        buttonView.setCompoundDrawablesWithIntrinsicBounds(scaleDrawable, null, null, null);
}
我最终做了这样的事:

Drawable drawable = getResources().getDrawable(R.drawable.cutlerywhite);
ScaleDrawable sd = new ScaleDrawable(drawable, Gravity.CENTER, iconScale, iconScale);
Drawable d1 = sd.getDrawable();
d1.setLevel(1);
sd.setLevel(1);
fnbButton.setCompoundDrawablesWithIntrinsicBounds(sd, null, null, null);

你能显示你的餐具白色和按钮布局的代码吗?为按钮添加了xml。餐具白色只是一个图像。你建议我在哪里调用此功能?
Drawable drawable = getResources().getDrawable(R.drawable.cutlerywhite);
ScaleDrawable sd = new ScaleDrawable(drawable, Gravity.CENTER, iconScale, iconScale);
Drawable d1 = sd.getDrawable();
d1.setLevel(1);
sd.setLevel(1);
fnbButton.setCompoundDrawablesWithIntrinsicBounds(sd, null, null, null);
Drawable drawableFnb = getResources().getDrawable(R.drawable.cutlerywhite);
Drawable drawableSunbed = getResources().getDrawable(R.drawable.logowhite);

ScaleDrawable sdFnb = new ScaleDrawable(drawableFnb, Gravity.LEFT, 1, 1);
ScaleDrawable sdSunbed = new ScaleDrawable(drawableSunbed, Gravity.LEFT, 1, 1);
Drawable d1 = sdFnb.getDrawable();
Drawable d2 = sdSunbed.getDrawable();

Dims fnbDims = getIconDims(drawableFnb);
Dims sunbedDims = getIconDims(drawableSunbed);

d1.setBounds(0, 0, fnbDims.getWidth(), fnbDims.getHeight());
d2.setBounds(0, 0, sunbedDims.getWidth(), sunbedDims.getHeight());

fnbButton.setCompoundDrawables(d1, null, null, null);
sunbedButton.setCompoundDrawables(d2, null, null, null);