控制布局,可以通过RelativeLayout.LayoutParams类
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.groups);
final TextView tv1 = new TextView(this);
tv1.setText("常用联系人");
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
lp1.addRule(RelativeLayout.BELOW, R.id.groups);
tv1.setLayoutParams(lp1);
linearLayout.addView(tv1, lp1);
也可采用linearLayout.addView(tv1, 0); // 线性布局 通过参数index控制加入的控件的位置
下面是friend_info_view.xml
chats_view_item.xml
效果图: