RelativeLayout用代码实现布局
TextView txt1 = new TextView(this);  
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,  
    LayoutParams.WRAP_CONTENT);  
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);  

    params.addRule(RelativeLayout.LEFT_OF, 1001);  
    txt1.setLayoutParams(params);

    TextView txt2 = new TextView(this);  
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams. WRAP_CONTENT,  
    LayoutParams.WRAP_CONTENT);  
    params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
    txt2.setLayoutParams(params2);  
    txt2.setText("obj");
    txt2.setId(1001);  
    
    RelativeLayout layout1 = new RelativeLayout(this);  
    layout1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  
    layout1.addView(txt1);  
    layout1.addView(txt2);  
    setContentView(layout1);



对应的XML:
<RelativeLayout  
    xmlns:andro></TextView>  
</RelativeLayout>

相关文章: