2012-08-14 59 views
0

我有一個代碼動態地在RelativeLayout(MyButton擴展按鈕並有一個setTaggetTag來設置ImageView)添加按鈕。按鈕可能有一個ImageView作爲圖標或沒有。來分配ImageView的按鈕(象圖標)ImageView分佈式

代碼:
//如果與圖標用戶組主題

if (this.isShowIcons() == true) { 
    if (newButton.getTag() != null) { 

     newButton.setCompoundDrawablesWithIntrinsicBounds(null, ((ImageView) newButton.getTag()).getDrawable(), null, null); 
     newButton.setPadding(leftpadding, toppadding, rightpadding, bottompadding); 
    } else { 
     newButton.setPadding(5, 5, 5, 5); 
    } 
} else { 
    newButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); 
    newButton.setPadding(5, 5, 5, 5); 
} 

事實證明,當我插入清單中的一行指定的目標和最小版本,圖標出現在按鈕內的底部位置。

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" /> 

如果我只是刪除行uses-sdk,適用於大多數設備,但佈局是例如一個問題:

的ImageView的樣品:

ImageView imb1 = new ImageView(this.getBaseContext()); 
imb1.setImageResource(R.drawable.icon_1); 
imb1.setMaxHeight(120); 
imb1.setMaxWidth(120); 
imb1.setScaleType(ImageView.ScaleType.CENTER); 

MyButton b1 = new MyButton(this); 
b1.setText("Label..."); 
b1.setId(1001); 
b1.setTag(imb1); 

任何人都可以幫我?

回答

0

解決方法:我在兩種情況下都刪除了填充,它工作。