1
 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);
        }

我需要创建 3 个文本视图(从用户创建博客上的帖子)每个 for 循环,如下所示:

帖子 1:

TextViewUSer TextViewDate

文本视图消息

帖子 2:

TextViewUSer TextViewDate

文本视图消息

我可以将一个博客的帖子(一组文本视图)放在另一个之上。我只是可以将它们定位,就像这样,从彼此。他们把一个粘在另一个上面。

我也用 addRules 验证了 .ABOVE 和其他人,但更糟糕的是,它们都卡在了左上角

4

1 回答 1

1

您可以像这样将规则添加到您的文本视图中

 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);

例如。

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)
于 2013-07-08T09:58:24.243 回答