这是我的LinearLayout中生成的按钮的arraylist,事实是,我已经在24x24中指出了大小,但是当我模仿它时,它根本没有调整大小。请帮助我,我会非常感谢它:D
public void generate_btnRemoveContact()
{
LinearLayout.LayoutParams lytContactParams=new LinearLayout.LayoutParams(24,24);
lytContactParams.weight=.5f;
btnRemoveContact.add(new ImageButton(getApplicationContext()));
btnRemoveContact.get(cntContact);
btnRemoveContact.get(cntContact).setScaleType(ImageView.ScaleType.FIT_CENTER);
btnRemoveContact.get(cntContact).setImageResource(R.drawable.ic_remove_circle_outline_red_24dp);
btnRemoveContact.get(cntContact).setBackgroundColor(Color.TRANSPARENT);
btnRemoveContact.get(cntContact).setTag(cntContact);
btnRemoveContact.get(cntContact).setId(cntContact);
btnRemoveContact.get(cntContact).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int rmvCnt = v.getId(); rmvCnt < cntContact; rmvCnt++) {
Toast.makeText(getApplicationContext(), "you selected " + rmvCnt, Toast.LENGTH_LONG).show();
}
}
});'
lytContact.addView(btnRemoveContact.get(cntContact));
cntContact++;
}
答案 0 :(得分:0)
根据您发布的代码,您需要在ImageButton上设置LayoutParams:
btnRemoveContact.get(cntContact).setLayoutParams(lytContactParams);