dandan
dandan

Reputation: 131

Relative Layout dynamic textView

 RelativeLayout layout = (RelativeLayout)findViewById(R.id.rl);
        for(int i = 1; i <= count; i++)
        {
            final TextView textViewUtente = new TextView(mContext);
            final TextView textViewMessaggio = new TextView(mContext);
            final TextView textViewData = new TextView(mContext);
            textViewUtente.setText(sepUser[i]);
            textViewMessaggio.setText(sepMessage[i]);
            textViewData.setText(sepDate[i]);
            int curTextViewIdUtente = 1000+i;
            int curTextViewIdMessaggio = 2000+i;
            int curTextViewIdData = 3000+i;
            textViewUtente.setId(curTextViewIdUtente);
            textViewMessaggio.setId(curTextViewIdMessaggio);
            textViewData.setId(curTextViewIdData);
            final RelativeLayout.LayoutParams params =
                    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                            RelativeLayout.LayoutParams.WRAP_CONTENT);



            params.topMargin= 100+i*150;

            textViewUtente.setLayoutParams(params);
            layout.addView(textViewUtente, params);

            params.topMargin= 250+i*150;

            textViewMessaggio.setLayoutParams(params);
            layout.addView(textViewMessaggio, params);

            params.topMargin= 100+i*150;
            params.rightMargin=200;
            textViewData.setLayoutParams(params);
            layout.addView(textViewData, params);
        }

I need to create 3 textview (that create the post on the blog from the user) every for loop like this:

Post 1:

TextViewUSer TextViewDate

TextViewMessage

Post 2:

TextViewUSer TextViewDate

TextViewMessage

I'm able to make one blog's post(a group of text view) above the other. I just can position them, like this, from eachother. they stuck one above the other.

I also trued with addRules the .ABOVE and others but it's even worst cause they stuck all on the top left corner

Upvotes: 1

Views: 1064

Answers (1)

Nirali
Nirali

Reputation: 13805

You can add Rules to your textviews like this

 tv1 = new TextView(this);
 tv1.setId((int)System.currentTimeMillis());

 RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);                
 lp.addRule(RelativeLayout.BELOW, recent.getId());

 tv1.setText("Time: "+System.currentTimeMillis());
 rr.addView(tv1, lp);

Egs.

lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId());
lp.addRule(RelativeLayout.BELOW, someOtherView.getId())
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT)

Upvotes: 1

Related Questions