0

ImageButtons の幅に問題があります。同じサイズではありません。すべての属性を 2 時間試しましたが、何もありませんでした。実行時にボタンを作成し、行の中に入れます (これも実行時に作成されます)。誰もこれに対する解決策を知っていますか? 代替テキスト

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));
                rows[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;
    }
4

1 に答える 1

1

これらの各行を同じ TableLayout に追加するか、そのような効果があると思いますか? その場合、行を別の行に関連付けて、ある行の最初の項目が別の行の最初の項目と同じ列になるようにします。

あなたの画像ではほとんどわかりませんが、画像の上部にある非常に切り取られたテキストが列の幅を押し上げて、最初のボタンを広げていると思います.

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

たまたま問題が発生した場合は、ボタンの行を他の種類のビューに配置することで修正できる可能性があります。

于 2010-11-02T01:58:46.703 に答える