RelativeLayout.TRUE有什么用

What is the use of RelativeLayout.TRUE

所以我有这个代码

RelativeLayout.LayoutParams positionRules = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    positionRules.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE);
    positionRules.addRule(RelativeLayout.ALIGN_RIGHT, RelativeLayout.TRUE);

里面那个RelativeLayout.TRUE有什么用?如果我将其设置为 false 会怎么样?

如果设置为FALSE,就好像规则不存在一样。所有这些 boolean 样式规则的默认行为是 FALSE.

您可以使用 xml 文件和 java 文件更改参数

xml:

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" >
   </RelativeLayout>

并在 java 文件中:

 RelativeLayout.LayoutParams positionRules = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    positionRules.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE);
    positionRules.addRule(RelativeLayout.ALIGN_RIGHT, RelativeLayout.TRUE);

If true, makes the right and buttom edge of this view match the right and buttom edge of the parent. else do nothing.

用于addRule(int verb, int subject)功能。

默认值为TRUE。如果将其设置为 FALSE,它将禁用规则。

并且根据 RelativeLayout.java#1408public void addRule(int verb) 称为 addRule(verb, TRUE)