Skip to main content
se eliminaron 21 caracteres en el cuerpo
Origen Enlace
Jorgesys
  • 111.1k
  • 14
  • 55
  • 134
    LinearLayout btnsContainer = new LinearLayout(getApplicationContext());
    btnsContainer.setLayoutParams(new LinearLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    btnsContainer.setOrientation(LinearLayout.VERTICAL);
    btnsContainer.setGravity(Gravity.CENTER);
    //Crea botons dinamicamente.
    for (int i = 0; i < 100; i++){
        final LinearLayout buttonContainer = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_button,null);
        ImageView btnImg = (ImageView) buttonContainer.findViewById(R.id.btn_image);
        TextView btnTxt = (TextView) buttonContainer.findViewById(R.id.btn_text);
        btnTxt.setText("mi Botón no." +  i);
        btnTxt.setBackgroundColor(getRandomColor());
        btnImg.setImageResource(R.mipmap.ic_launcher);
        buttonContainer.setTag(i);

        buttonContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                   Toast.makeText(getApplicationContext(), " Listener botón " + v.getTag() + " id: " + v.getId(), Toast.LENGTH_SHORT).show();
            }
        });
        //Va agregegando botones al contenedor.
        btnsContainer.addView(buttonContainer);
    }
    //Crea contenedor para agregar contenedor de botones.
    FrameLayout.LayoutParams paramsContainer = new FrameLayout.LayoutParams(400, 1500, Gravity.CENTER);
    //Agrega contenedor con botones.
    addContentView(btnsContainer, paramsContainer);
    LinearLayout btnsContainer = new LinearLayout(getApplicationContext());
    btnsContainer.setLayoutParams(new LinearLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    btnsContainer.setOrientation(LinearLayout.VERTICAL);
    btnsContainer.setGravity(Gravity.CENTER);
    //Crea botons dinamicamente.
    for (int i = 0; i < 100; i++){
        final LinearLayout buttonContainer = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_button,null);
        ImageView btnImg = (ImageView) buttonContainer.findViewById(R.id.btn_image);
        TextView btnTxt = (TextView) buttonContainer.findViewById(R.id.btn_text);
        btnTxt.setText("mi Botón no." +  i);
        btnTxt.setBackgroundColor(getRandomColor());
        btnImg.setImageResource(R.mipmap.ic_launcher);
        buttonContainer.setTag(i);

        buttonContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                   Toast.makeText(getApplicationContext(), " Listener botón " + v.getTag() + " id: " + v.getId(), Toast.LENGTH_SHORT).show();
            }
        });
        //Va agregegando botones al contenedor.
        btnsContainer.addView(buttonContainer);
    }
    //Crea contenedor para agregar contenedor de botones.
    FrameLayout.LayoutParams paramsContainer = new FrameLayout.LayoutParams(400, 1500, Gravity.CENTER);
    //Agrega contenedor con botones.
    addContentView(btnsContainer, paramsContainer);
    LinearLayout btnsContainer = new LinearLayout(getApplicationContext());
    btnsContainer.setLayoutParams(new LinearLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    btnsContainer.setOrientation(LinearLayout.VERTICAL);
    btnsContainer.setGravity(Gravity.CENTER);
    //Crea botons dinamicamente.
    for (int i = 0; i < 100; i++){
        final LinearLayout buttonContainer = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_button,null);
        ImageView btnImg = (ImageView) buttonContainer.findViewById(R.id.btn_image);
        TextView btnTxt = (TextView) buttonContainer.findViewById(R.id.btn_text);
        btnTxt.setText("mi Botón no." +  i);
        btnTxt.setBackgroundColor(getRandomColor());
        btnImg.setImageResource(R.mipmap.ic_launcher);
        buttonContainer.setTag(i);

        buttonContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                   Toast.makeText(getApplicationContext(), " Listener botón " + v.getTag() , Toast.LENGTH_SHORT).show();
            }
        });
        //Va agregegando botones al contenedor.
        btnsContainer.addView(buttonContainer);
    }
    //Crea contenedor para agregar contenedor de botones.
    FrameLayout.LayoutParams paramsContainer = new FrameLayout.LayoutParams(400, 1500, Gravity.CENTER);
    //Agrega contenedor con botones.
    addContentView(btnsContainer, paramsContainer);
se añadieron 25 caracteres en el cuerpo
Origen Enlace
Jorgesys
  • 111.1k
  • 14
  • 55
  • 134
    LinearLayout btnsContainer = new LinearLayout(getApplicationContext());
    btnsContainer.setLayoutParams(new LinearLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    btnsContainer.setOrientation(LinearLayout.VERTICAL);
    btnsContainer.setGravity(Gravity.CENTER);
    //Crea botons dinamicamente.
    for (int i = 0; i < 100; i++){
        final LinearLayout buttonContainer = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_button,null);
        ImageView btnImg = (ImageView) buttonContainer.findViewById(R.id.btn_image);
        TextView btnTxt = (TextView) buttonContainer.findViewById(R.id.btn_text);
        btnTxt.setText("mi Botón no." +  i);
        btnTxt.setBackgroundColor(getRandomColor());
        btnImg.setImageResource(R.mipmap.ic_launcher);
        buttonContainer.setTag(i);

        buttonContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                   Toast.makeText(getApplicationContext(), " Listener botón " + v.getTag() + " id: " + v.getId(), Toast.LENGTH_SHORT).show();
            }
        });
        //Va agregegando botones al contenedor.
        btnsContainer.addView(buttonContainer);
    }
    //Crea contenedor para agregar contenedor de botones.
    FrameLayout.LayoutParams paramsContainer = new FrameLayout.LayoutParams(400, 1500, Gravity.CENTER);
    //Agrega contenedor con botones.
    addContentView(btnsContainer, paramsContainer);
    LinearLayout btnsContainer = new LinearLayout(getApplicationContext());
    btnsContainer.setLayoutParams(new LinearLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    btnsContainer.setOrientation(LinearLayout.VERTICAL);
    btnsContainer.setGravity(Gravity.CENTER);
    //Crea botons dinamicamente.
    for (int i = 0; i < 100; i++){
        final LinearLayout buttonContainer = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_button,null);
        ImageView btnImg = (ImageView) buttonContainer.findViewById(R.id.btn_image);
        TextView btnTxt = (TextView) buttonContainer.findViewById(R.id.btn_text);
        btnTxt.setText("mi Botón no." +  i);
        btnTxt.setBackgroundColor(getRandomColor());
        btnImg.setImageResource(R.mipmap.ic_launcher);
        buttonContainer.setTag(i);

        buttonContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), " Listener botón " + v.getTag(), Toast.LENGTH_SHORT).show();
            }
        });
        //Va agregegando botones al contenedor.
        btnsContainer.addView(buttonContainer);
    }
    //Crea contenedor para agregar contenedor de botones.
    FrameLayout.LayoutParams paramsContainer = new FrameLayout.LayoutParams(400, 1500, Gravity.CENTER);
    //Agrega contenedor con botones.
    addContentView(btnsContainer, paramsContainer);
    LinearLayout btnsContainer = new LinearLayout(getApplicationContext());
    btnsContainer.setLayoutParams(new LinearLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    btnsContainer.setOrientation(LinearLayout.VERTICAL);
    btnsContainer.setGravity(Gravity.CENTER);
    //Crea botons dinamicamente.
    for (int i = 0; i < 100; i++){
        final LinearLayout buttonContainer = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_button,null);
        ImageView btnImg = (ImageView) buttonContainer.findViewById(R.id.btn_image);
        TextView btnTxt = (TextView) buttonContainer.findViewById(R.id.btn_text);
        btnTxt.setText("mi Botón no." +  i);
        btnTxt.setBackgroundColor(getRandomColor());
        btnImg.setImageResource(R.mipmap.ic_launcher);
        buttonContainer.setTag(i);

        buttonContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                   Toast.makeText(getApplicationContext(), " Listener botón " + v.getTag() + " id: " + v.getId(), Toast.LENGTH_SHORT).show();
            }
        });
        //Va agregegando botones al contenedor.
        btnsContainer.addView(buttonContainer);
    }
    //Crea contenedor para agregar contenedor de botones.
    FrameLayout.LayoutParams paramsContainer = new FrameLayout.LayoutParams(400, 1500, Gravity.CENTER);
    //Agrega contenedor con botones.
    addContentView(btnsContainer, paramsContainer);
se añadieron 18 caracteres en el cuerpo
Origen Enlace
Jorgesys
  • 111.1k
  • 14
  • 55
  • 134

Este sería el layout del botón personalizado item_button.xml:

Este sería el layout del botón personalizado:

Este sería el layout del botón personalizado item_button.xml:

se añadieron 210 caracteres en el cuerpo
Origen Enlace
Jorgesys
  • 111.1k
  • 14
  • 55
  • 134
Loading
Origen Enlace
Jorgesys
  • 111.1k
  • 14
  • 55
  • 134
Loading