Reputation: 1702
Why doesn't it work? "First" overlapped "Second". What's wrong?
protected View onCreateDialogView() {
RelativeLayout layout = new RelativeLayout(mContext);
RelativeLayout.LayoutParams mParams = new RelativeLayout.LayoutParams (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mFirstText = new TextView(mContext);
mSecondText.setId(1);
mSecondText = new TextView(mContext);
mSecondText.setId(2);
mParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, mFirstText.getId());
mParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, mSecondText.getId());
setText(mFirstText, "First");
setText(mSecondText, "Second");
layout.addView(mFirstText, mParams);
layout.addView(mSecondText, mParams);
return layout;
}
Upvotes: 0
Views: 393
Reputation: 200090
What if you change this:
RelativeLayout.LayoutParams mParams = new
RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
To this:
RelativeLayout.LayoutParams mParams = new
RelativeLayout.LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
By the way... why don't you use a XML layout instead of doing it from the Java code?
Upvotes: 1