Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/04/2015, 09:55
Avatar de Maverick2786
Maverick2786
 
Fecha de Ingreso: diciembre-2012
Mensajes: 107
Antigüedad: 11 años, 4 meses
Puntos: 1
Botones en varias columnas

Como se puede ver en la imagen:

Tengo en una sola columna todos lo botones, lo que quiero que esten en varias columnas.

Los botones los genero dinamicamente por medio de una consulta
El metod que genera los botones:
Código Java:
Ver original
  1. private void createEmpresas() {
  2.         Button b;
  3.         JSONObject json = null;
  4.         int count = 0;
  5.         LinearLayout lm = (LinearLayout) findViewById(R.id.linearMain);
  6.         JSONObject jobj = obj_sqlite.get_descripcion_empresas();
  7.  
  8.         try {
  9.             count = Integer.parseInt(jobj.getString("cont"));
  10.             json = new JSONObject(jobj.getString("json"));
  11.         } catch (Exception e) {
  12.             Log.e("getParams", e.getMessage());
  13.         }
  14.  
  15.         for (int x = 1; x <= count; x++) {
  16.  
  17.             try {
  18.                 JSONObject json_row = new JSONObject(json.getString("row" + x));
  19.                
  20.                 b = new Button(this);
  21.                 b.setText(json_row.getString("descripcion"));
  22.                 b.setId(json_row.getInt("empresa"));
  23.                 b.setTextSize(10);
  24.                 b.setPadding(8, 3, 8, 3);
  25.                 b.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);
  26.                 b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
  27.                         LayoutParams.WRAP_CONTENT));
  28.  
  29.                 lm.addView(b);
  30.  
  31.                 b.setOnClickListener(new View.OnClickListener() {
  32.                     public void onClick(View v) {
  33.                         // TODO Auto-generated method stub
  34.                         Toast.makeText(getApplicationContext(),
  35.                                 "Yipee.." +v.getId(), Toast.LENGTH_SHORT)
  36.                                 .show();
  37.                     }
  38.                 });
  39.             } catch (Exception e) {
  40.                 Log.e("getParams", e.getMessage());
  41.             }
  42.         }
  43.     }

Y este es mi xml:
Código XML:
Ver original
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    xmlns:tools="http://schemas.android.com/tools"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:background="@color/bg_main"
  6.    android:paddingBottom="@dimen/activity_vertical_margin"
  7.    android:paddingLeft="@dimen/activity_horizontal_margin"
  8.    android:paddingRight="@dimen/activity_horizontal_margin"
  9.    android:paddingTop="@dimen/activity_vertical_margin"
  10.    tools:context="com.example.php_mysql_sqlite.MainActivity" >
  11.  
  12.     <Button
  13.        android:id="@+id/button4"
  14.        style="?android:attr/buttonStyleSmall"
  15.        android:layout_width="wrap_content"
  16.        android:layout_height="wrap_content"
  17.        android:layout_alignBaseline="@+id/button6"
  18.        android:layout_alignBottom="@+id/button6"
  19.        android:layout_alignParentRight="true"
  20.        android:layout_marginRight="17dp"
  21.        android:background="@null"
  22.        android:onClick="loginOut"
  23.        android:text="@string/btLogOut"
  24.        android:textColor="@color/Red" />
  25.  
  26.     <Button
  27.        android:id="@+id/button6"
  28.        style="?android:attr/buttonStyleSmall"
  29.        android:layout_width="wrap_content"
  30.        android:layout_height="wrap_content"
  31.        android:layout_alignBaseline="@+id/button5"
  32.        android:layout_alignBottom="@+id/button5"
  33.        android:layout_centerHorizontal="true"
  34.        android:onClick="syncSqliteMysql"
  35.        android:text="@string/syn" />
  36.  
  37.     <Button
  38.        android:id="@+id/button5"
  39.        style="?android:attr/buttonStyleSmall"
  40.        android:layout_width="wrap_content"
  41.        android:layout_height="wrap_content"
  42.        android:layout_alignParentBottom="true"
  43.        android:layout_alignParentLeft="true"
  44.        android:onClick="borrarTabla"
  45.        android:text="@string/delTable" />
  46.  
  47.     <ScrollView
  48.        android:layout_width="285dp"
  49.        android:layout_height="330dp"
  50.        android:layout_marginTop="1dp" >
  51.  
  52.         <LinearLayout
  53.            android:id="@+id/linearMain"
  54.            android:layout_width="fill_parent"
  55.            android:layout_height="fill_parent"
  56.            android:layout_alignLeft="@+id/button5"
  57.            android:layout_alignParentTop="true"
  58.            android:layout_alignRight="@+id/button4"
  59.            android:background="@color/White"
  60.            android:orientation="vertical" >
  61.         </LinearLayout>
  62.     </ScrollView>
  63.  
  64. </RelativeLayout>

Gracias a todos