Ich bekomme dynamische Länge des String-Array und ich möchte Bilder in der ImageButton anzeigen und das auch in der horizontalen Ansicht, wie ich Button hinzugefügt hatte, aber es zeigt in der vertikalen Layout.Bitte helfen. Das ist mein Code:dynamisch hinzufügen imagebutton programmatisch android
for (int i =0;i<adapt_objmenu.image_array.length;i++){
ImageButton b1 = new ImageButton(myrefmenu);
b1.setId(100 + i);
// b1.setText(adapt_objmenu.city_name_array[i]);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if (i > 0) {
lp.addRule(RelativeLayout.BELOW, b1.getId() - 1);
}
b1.setLayoutParams(lp);
relative.addView(b1);
//relate.addView(b1, i, new RelativeLayout.LayoutParams(width,height));
//height = height+80;
}
Sie erkennen Sie Einstellung 'RelativeLayout.BELOW', während' RelativeLayout.RIGHT_OF' würde mehr Sinn machen, wenn ich das richtig verstehe Ihre Frage? –
ok ich habe das aber, wie man Bild auf dem imagebutton setzt, das ist die Hauptfrage – Ved
du meinst, du möchtest Bild einstellen, nachdem 'ImageButton' in' RelativeLayout' hinzugefügt wurde. – Herry