views:

72

answers:

1

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;
      }
+1  A: 

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?

Cristian
Nothing. It's just stretch my Dialog widget around the screen.
Scit
One more question. How should I return a layout (line #20) if I realized it in xml file?
Scit
Use `LayoutInflater`. You can find a lot of examples on Google.
Cristian
Thank you. I've done!
Scit