Android Realtivelayout加载项表格行

Android Realtivelayout加载项表格行,android,dynamic,android-relativelayout,Android,Dynamic,Android Relativelayout,它什么也没给我。。如果我遗漏了一些东西,任何人都可以帮我整理它,而不是显示我添加到相对布局中的图像以及文本视图 RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams (LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); tParams.addRule(RelativeLayout.CENTER_

它什么也没给我。。如果我遗漏了一些东西,任何人都可以帮我整理它,而不是显示我添加到相对布局中的图像以及文本视图

     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);
RelativeLayout.LayoutParams tParams=新的RelativeLayout.LayoutParams
(LayoutParams.WRAP_内容,LayoutParams.WRAP_内容);
tParams.addRule(RelativeLayout.CENTER_HORIZONTAL,RelativeLayout.TRUE);
tParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);
LayoutParams rlParams=新的LayoutParams(LayoutParams.FILL\u父级
,LayoutParams.FILL\u PARENT);
对于(int i=0;i
}

我解决了我的问题。。在tow中添加布局时,我不会添加布局参数:)

package com.example.test;
导入android.app.Activity;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.ViewGroup.LayoutParams;
导入android.widget.ImageView;
导入android.widget.RelativeLayout;
导入android.widget.TableRow;
导入android.widget.TextView;
公共类MainActivity扩展了活动{
表格行;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rows=(TableRow)findviewbyd(R.id.rows);
RelativeLayout.LayoutParams tParams=新的RelativeLayout.LayoutParams(
LayoutParams.WRAP_内容,LayoutParams.WRAP_内容);
tparms.addRule(相对左对齐);
对于(int i=0;i<10;i++){
TextView txt=新的TextView(此);
txt.setText(“+i”);
setId(i+1);
RelativeLayout rLayout=新的RelativeLayout(本);
txt.setLayoutParams(tParams);
//将TextView作为子对象添加到RelativeLayout
ImageView图像=新的ImageView(此);
setImageResource(R.drawable.ic_启动器);
RelativeLayout.LayoutParams iParms=新的RelativeLayout.LayoutParams(
20, 20);
iparms.addRule(RelativeLayout.RIGHT_OF,i+1);
image.setLayoutParams(iParms);
rLayout.addView(图像);
rLayout.addView(txt);
rows.addView(rLayout);
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.activity\u主菜单);
返回true;
}
}
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;
    }
}