【发布时间】:2013-01-02 06:21:06
【问题描述】:
我使用表格布局来使用权重来布局按钮,按钮的大小为 0dip 或 wrap_content,因此它们会按其权重展开。
我正在尝试将按钮转换为 ImageButton 并将图像设置为按钮大小而不是展开它。
我让按钮被创建并获取它的大小,然后我分配图像并使用 ImageButton.setMaxHeight(); 限制它的高度;
final ImageButton ib = (ImageButton) findViewById(R.id.buttonOptions);
ib.post(new Runnable() {
public void run() {
final int height = ib.getHeight();
ib.setScaleType(ScaleType.FIT_CENTER);
ib.setMaxHeight(5); // or height
ib.setImageResource(R.drawable.options);
}});
图像正以其原始大小绘制,因此展开按钮... setMaxHeight() 不限制图像的高度/宽度。知道为什么吗?
【问题讨论】:
标签: android height imagebutton image-scaling