0

它没有给我任何东西..在我错过任何东西的地方,任何人都可以帮助我整理它,而不是显示图像以及我添加到相对布局中的文本视图

     RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams
                 (LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
         tParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
         tParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);

         LayoutParams rlParams = new LayoutParams(LayoutParams.FILL_PARENT
                 ,LayoutParams.FILL_PARENT); 



                    for (int i=0; i < Math.ceil(MyContants.servicemodellist.size() / 2); i++) {
                        TextView txt= new TextView(RoomservicsFirstPage.this);
                        txt.setText(MyContants.servicemodellist.get(i).getOption_text_1());

                         RelativeLayout rLayout = new RelativeLayout(RoomservicsFirstPage.this);
                         txt.setLayoutParams(tParams);
                         rLayout.setLayoutParams(rlParams);
                            // Adding the TextView to the RelativeLayout as a child
                        ImageView image = new ImageView(RoomservicsFirstPage.this);

                         image.setLayoutParams(rlParams);
                         download(MyContants.servicemodellist.get(i).getImage(),image);
                         rLayout.addView(image);
                         rLayout.addView(txt);
                        rows.addView(rLayout);

}

我解决了我的问题..在拖曳中添加布局时我没有添加布局参数:)

4

1 回答 1

1
package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends Activity {
    TableRow rows;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rows = (TableRow) findViewById(R.id.rows);
        RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        tParams.addRule(RelativeLayout.ALIGN_LEFT);

        for (int i = 0; i < 10; i++) {
            TextView txt = new TextView(this);
            txt.setText("" + i);
            txt.setId(i + 1);
            RelativeLayout rLayout = new RelativeLayout(this);
            txt.setLayoutParams(tParams);
            // Adding the TextView to the RelativeLayout as a child
            ImageView image = new ImageView(this);
            image.setImageResource(R.drawable.ic_launcher);
            RelativeLayout.LayoutParams iParams = new RelativeLayout.LayoutParams(
                    20, 20);
            iParams.addRule(RelativeLayout.RIGHT_OF, i + 1);

            image.setLayoutParams(iParams);
            rLayout.addView(image);
            rLayout.addView(txt);
            rows.addView(rLayout);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
于 2013-05-29T12:19:47.713 回答