[英]Android Studio: in an xml attribute, what exactly does the vertical bar mean?
I am confused as to what exactly the | 我对到底是什么感到困惑。 means in the following context:
在以下情况下表示:
android:layout_gravity="center_vertical|center_horizontal"
Is the definition of the use of this symbol specified anywhere, in case I come across others? 万一遇到其他人,是否在任何地方指定了此符号的使用定义?
It means that it has both flags enabled, center_vertical and center_horizontal. 这意味着它同时启用了center_vertical和center_horizontal两个标志。
In the Java side, the pipe is a bitwise OR operation, which is commonly used to store flags, which are then checked using a bitwise AND (& operator) operation. 在Java端,管道是按位或运算,通常用于存储标志,然后使用按位与 (&运算符)操作对其进行检查。
android:layout_gravity
determines gravity which view specifies to its parent thus position which it would like to "take" in the parent to which it belongs to. android:layout_gravity
确定重力,该重力将视图指定给其父对象,从而确定其在其所属父对象中要“占据”的位置。
Generally you can read about attributes at Android dev site: https://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html 通常,您可以在Android开发者网站上阅读有关属性的信息: https : //developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html
Some attributes accept more than one value, like layout_gravity. 一些属性接受多个值,例如layout_gravity。 The |
| character separe these values, in that case meaning that your layout gonna take both gravities, center_vertical and center_horizontal.
字符分隔这些值,在这种情况下,这意味着您的布局将同时具有center_vertical和center_horizontal两个重力。 You could simply this by using:
您可以使用以下方法简单地做到这一点:
android:layout_gravity="center"
You can combine this constants in order to position your content in relation to it parent: https://developer.android.com/reference/android/R.attr.html#layout_gravity 您可以结合使用这些常量,以便将内容相对于其父对象定位: https : //developer.android.com/reference/android/R.attr.html#layout_gravity
Other examples of attributes that take more than one value: 具有多个值的其他属性示例:
android:gravity="left|bottom"
android:inputType="textMultiLine|textCapSentences"
android:gravity="left|bottom"
android:foregroundGravity="fill_horizontal|top"
android:inputType="text|textAutoComplete|textNoSuggestions"
android:windowSoftInputMode="adjustResize|stateHidden"
android:configChanges="keyboardHidden|orientation|screenSize"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.