这些图片(图标)大致相同大小,但我需要调整它们的大小,以便按钮保持相同的高度。
我该怎么做?
Button button = new Button(this);
button.setText(apiEventObject.getTitle());
button.setOnClickListener(listener);
/*
* set clickable id of button to actual event id
*/
int id = Integer.parseInt(apiEventObject.getId());
button.setId(id);
button.setLayoutParams(new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
Drawable drawable = LoadImageFromWebOperations(apiSizeObject.getSmall());
//?resize drawable here? drawable.setBounds(50, 50, 50, 50);
button.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
setCompoundDrawables()
? “Intrinsic” 在 Android 中的其他位置中指的是原始图像大小,例如Drawable.getIntrinsicHeight()
。 - William T. Mallard