android代码设置below,纯用代码开展安卓布局,为什么RelativeLayout.BELOW这个设置不起作用...

纯用代码进行安卓布局,为什么RelativeLayout.BELOW这个设置不起作用

private int receiverid=0;

private int msgid=1;

private int btnid=2;

public AppTalk(Context context,ISystemMethods iSystemMethods) {

super(context);

this.parentContext=context;

this.ParentiCommunication=iSystemMethods;

this.mainlayout=new RelativeLayout(parentContext);

this.mainlayout.setBackgroundColor(Color.CYAN);

init();

}

void init(){

//本类RelativeLayout的布局管理器

LayoutParams lpmain=new LayoutParams(400,400);

//创建提示框容器

LinearLayout receivelayout=new LinearLayout(parentContext);

receivelayout.setId(receiverid);

LayoutParams lpreceivelayout=new LayoutParams(-1,50);

lpreceivelayout.addRule(RelativeLayout.ALIGN_PARENT_TOP);

//创建提示框

TextView showreceive=new TextView(parentContext);

//显示与xxx的聊天框等文字提示

showreceive.setText("与xxxx正在进行聊天");

showreceive.setTextColor(Color.RED);

LayoutParams lpreceive=new LayoutParams(-1,-1);

receivelayout.addView(showreceive,lpreceivelayout);

//showmsg和inputmsg的父级容器

LinearLayout msglayout=new LinearLayout(parentContext);

msglayout.setId(msgid);

msglayout.setBackgroundColor(Color.BLUE);

LayoutParams lpmsg=new LayoutParams(400,350);

lpmsg.addRule(RelativeLayout.BELOW,receiverid);//这句为什么不起作用?

//我的本意试想放在receivelayout这个提示的下面的,结果msglayout排在最上面了

mainlayout.addView(receivelayout);

mainlayout.addView(msglayout,lpmsg);

addView(mainlayout, lpmain);

//mainlayout.addView(msg,new LayoutParams(-1, -2));

}

分享到:

------解决方案--------------------

两个relativelayout上下如下面列子

LinearLayout ll = new LinearLayout(this);

ll.setBackgroundColor(Color.RED);

ll.setLayoutParams(new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT));

RelativeLayout rl = new RelativeLayout(this);

rl.setBackgroundColor(Color.BLUE);

rl.setLayoutParams(new RelativeLayout.LayoutParams(100,100));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值