开发者

ImageButton isn't the same size

I have problem with width of ImageButtons, it isn't the same size. I have experimented with all attributes for two hours and nothing. I create buttons at runtime and put inside row (also created at runtime). Does anybody know any solution for this ?

ImageButton isn't the same size

public static TableRow[] Create(List<Apartment> list){
        TableRow[] rows=null;
        try{
            rows=new TableRow[list.size()*3];
            int i=0;

            for(final Apartment ap : list){
                rows[3*i]=new TableRow(activity);
                rows[3*i+1]=new TableRow(activity);
                rows[3*i+2]=new TableRow(activity);

                rows[3*i].setLayoutParams(new LayoutParams( 
                        LayoutParams.WRAP_CONTENT, 
                        LayoutParams.FILL_PARENT));
                rows[3*i+1].setLayoutParams(new LayoutParams( 
                        LayoutParams.WRAP_CONTENT, 
                        LayoutParams.FILL_PARENT));
                rows[3*i+2].setLayoutParams(new LayoutParams( 
                        LayoutParams.WRAP_CONTENT, 
                        LayoutParams.FILL_PARENT));

                rows[3*i].setBackgroundColor(color_background[(i%2)]);
                rows[3*i+1].setBackgroundColor(color_background[(i%2)]);
                rows[3*i+2].setBackgroundColor(color_background[(i%2)]);

                TextView txtMainInform=new TextView(activity);
                txtMainInform.setText(ap.GetMainInformation());
                txtMainInform.setLayoutParams(new LayoutParams( 
                        LayoutParams.WRAP_CONTENT, 
                        LayoutParams.WRAP_CONTENT));
                rows[3*i].addView(txtMainInform);
                rows[3*i].setVisibility(1);

                TextView txtMoreInform=new TextView(activity);
                txtMoreInform.setText(ap.GetMoreInformation());
                txtMoreInform.setLayoutParams(new LayoutParams( 
                        LayoutParams.WRAP_CONTENT, 
                        LayoutParams.WRAP_CONTENT));
                row开发者_开发百科s[3*i+1].addView(txtMoreInform);

                ImageButton imbCall=new ImageButton(activity);
                imbCall.setImageResource(R.drawable.phone);
                imbCall.setOnClickListener(new OnClickListener() {  

                    public void onClick(View v) {
                         if(ap.GetContact()!=null){
                          try {
                            activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ap.GetContact())));
                          } catch (Exception e) {
                            e.printStackTrace();
                          }
                        }
                    }
                });
                imbCall.setMaxWidth(24);
                imbCall.setMinimumWidth(22);

                ImageButton imbGallery=new ImageButton(activity);
                imbGallery.setMaxWidth(24);
                imbGallery.setMinimumWidth(22);
                imbGallery.setImageResource(R.drawable.gallery_icon);


                ImageButton imbMap=new ImageButton(activity);
                imbMap.setImageResource(R.drawable.map);
                imbMap.setMaxWidth(24);  
                imbMap.setMinimumWidth(22);
                imbMap.setOnClickListener(new OnClickListener() {  

                    public void onClick(View v) {
                           Intent i = new Intent(activity,ResultMap.class);
                           activity.startActivity(i);
                    }  
                });

                ImageButton imbWay=new ImageButton(activity);
                imbWay.setMaxWidth(24);
                imbWay.setMinimumWidth(22);
                imbWay.setImageResource(R.drawable.walker);

                rows[3*i+2].addView(imbCall);
                rows[3*i+2].addView(imbGallery);
                rows[3*i+2].addView(imbMap);
                rows[3*i+2].addView(imbWay);
                i++;
            }

        }
        catch(Exception e){

        }
        return rows;
    }


I would guess that you add each of those rows into the same TableLayout, or something to that effect? If so, it would associate the rows with another, so that the first item in one row is in the same column as the first item in another row.

I can barely tell by your image, but my guess would be that the extremely cut-off text at the top of the image is pushing the width of the column, widening the first button with it.

|longish text blagh |       |       |       |
|price              |       |       |       |
|blah               |       |       |       |
| [------BTN------] | [BTN] | [BTN] | [BTN] |

You could possibly fix it by putting the row of buttons into some other sort of view, if that happens to be the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜