Problema de distribución con el margen del botón
Tengo problemas con la organización del diseño en la aplicación de Android. Estoy creando dinámicamente botones y agregándolos con este código a mi diseño:
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0; i < NO_NUMBERS; i++){
Button btn = new Button(this);
btn = (Button) layoutInflater.inflate(R.layout.button, null);
btn.setId(2000+i);
Integer randomNumber = sort.getNumbersCopy()[i];
btn.setText(randomNumber.toString());
btn.setOnClickListener((OnClickListener) this);
buttonList.addView(btn);
list.add(btn);
}
Lo estoy agregando a LinearLayout:
<LinearLayout
android:id="@+id/buttonlist"
android:layout_alignParentLeft="true"
android:layout_marginTop="185dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
y estoy importando este .xml donde estoy definiendo el diseño del botón:
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:textSize="26dp"
android:textStyle ="bold"
android:textColor="#ffffff"
android:background="@drawable/button"
android:layout_marginLeft="8px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
Bueno, el diseño siempre termina así:
En lugar de algo como esto (incluso spce entre botones, botones cuadrados):
Para resumir esto: tengo que:
describe botón en xml generar dinámicamente N botonesadd propiedades del botón descrito a los creados dinámicamenteorganice el diseño para que pueda distribuir uniformemente los botones en buttonList con espacios entre tham