2013-01-15 34 views
2

我想創建一個imagebutton,但圖像不填充圖像按鈕。圖像與圖像按鈕具有相同的尺寸。 imagebutton具有正確的尺寸,它看起來像imagebutton有填充?!Android/Monodroid圖像比imagebutton小

我嘗試了大部分的scaletypes。

我的代碼:

ImageButton ib = new ImageButton(Context); 
AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams((int)getWidth(3), (int)rowHeight, (int)offsetValue, (int)(offsetRow+row*rowHeight)); 

Stream bitmap = act.Assets.Open("somefolder/" + name + ".gif"); 
Bitmap bMap = Android.Graphics.BitmapFactory.DecodeStream(bitmap); 

bMap = Bitmap.CreateScaledBitmap(bMap, (int)getWidth(3), (int)rowHeight, false); 


ib.SetScaleType(ImageButton.ScaleType.FitXy); 
ib.SetAdjustViewBounds(true); 
ib.SetImageBitmap(bMap); 

bitmap = null; 
bMap = null; 

ib.LayoutParameters = lp; 

layout.AddView(ib); 

回答

2

呀它的填充或類似的東西,我想,以允許用戶進行密碼可視創造一個EditText一個按鈕,並有同樣的問題。 ..直到現在還沒有找到解決方案。
因爲你是我嘗試使用電子書籍的ImageView的,使其可點擊比你有相同的功能,就像一個ImageButton的,什麼

在Android框架定義 ImageButton
+0

謝謝你,工作正常,完全相同的參數。奇怪爲什麼它不能與imagebutton一起使用。 ^^ – anguish

+0

問我關於那個.... EditText它仍然嚇到我了 – Nickolaus

0

標準9補丁繪製有內容填充它不允許您使用按鈕內的所有空間。要解決此問題,請使用自己的背景可繪製(將其設置爲android:background="@drawable/..."屬性)或調整您在android:src屬性中設置的可繪製對象。

請參閱this article瞭解有關如何通過9修補程序繪圖定義內容填充的更多信息。