ScaleType on ImageButton results in tiny image

Hi I have a grid ImageButton

that scales to the display width and contains a PNG file as an image. I add all of this to a linear layout like:

public void createButtons(){

            int buttonX = 9;
            int buttonY = 9;
            int size    = 80;
            int tag     = 0;

          TableLayout layout = new TableLayout (this);
          layout.setLayoutParams( new TableLayout.LayoutParams(900,900) );
          layout.setPadding(1,1,1,1);
          layout.setBackgroundColor(0xff00af00); //green

          RelativeLayout ll = (RelativeLayout)findViewById(R.id.rel);
          ll.addView(layout);

          for(int x=0;x<buttonX;x++)    {

              TableRow tr = new TableRow(this);                     
              for(int y=0;y<buttonY;y++)    {
                but[x][y] = new ImageButton(this); 
                but[x][y].setBackgroundColor(0xff0000af); //blue
                but[x][y].setImageResource(R.drawable.buttonmask3); 
                     but[x][y].setScaleType(ImageButton.ScaleType.CENTER_INSIDE); 
                tr.addView(but[x][y], height/10,height/10);
                }
                layout.addView(tr);
            }
}  

      

The problem is that the layout now looks like this:

does

whereas it should look like this:

should

(this one was a quick Photoshop, but you get the idea that the scale should fill the button completely)

What can I do with these tiny images? I have tried CENTER_INSIDE , FITXY and all other ScaleTypes but I have no luck so far: /

width

taken from the screen width (or height in landscape)

buttonmask3.png is 170 * 170px .

+3


source to share


1 answer


The problem is with the supplement that ImageButton

comes naturally.

addition

but[x][y].setPadding(0, 0, 0, 0);

      



together with

but[x][y].setScaleType(ImageButton.ScaleType.CENTER_CROP); 

      

Solved this for me.

+2


source







All Articles