小编Sof*_*dea的帖子

如何以编程方式在相对布局中设置TextViews的align parent right属性

我有一个以编程方式创建的相对布局:

 RelativeLayout layout = new RelativeLayout( this );
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
        LayoutParams.WRAP_CONTENT);
Run Code Online (Sandbox Code Playgroud)

现在我有两个 TextView,我想在这个相对布局中添加它们。但问题是两个 TextViews 都显示在相对布局的左侧,彼此重叠。

textViewContainer.addView(textView1);
textViewContainer.addView(textView2);
Run Code Online (Sandbox Code Playgroud)

现在我想知道如何以编程方式设置

`android:layout_alignParentRight="true"`
Run Code Online (Sandbox Code Playgroud)

或者

`android:layout_toLeftOf="@id/textView"` 
Run Code Online (Sandbox Code Playgroud)

TextViews 的属性,就像我们在 xml 中所做的那样?

java xml android layoutparams android-relativelayout

2
推荐指数
1
解决办法
8003
查看次数