0

我想确认 Android XML 文件中的按位运算符。例如这一行

android:layout_gravity="center_horizontal|bottom"

我应该怎么读?继承自 Java 或 Android 的规则是否对位运算符有自己的解释?

是否支持所有位运算符?如果是的话,你能告诉我其他运营商的例子吗(链接也很好)?

谢谢

4

2 回答 2

2
2|1 = 3
2&1 = 0
3&1 = 1

central_horizo​​ntal, bottom 是整数,所以你可以使用这个结构

    int center_horizontal = 0x05; //just for clarification
    int other_orientation = 0x10;
    int orietntation = center_horizontal | other_orientation;

//this condition returns true
    if((orientation&center_horizontal)==center_horizontal){
        //something to do
        }
于 2011-06-23T17:03:56.907 回答
1

的值android_layout_gravity由 Android 代码解析。如此处所述,此处唯一认可的运算符是|. 我不相信解释|为按位或运算符是规范的一部分。(例如,center_horizontal是 0x05 和right0x01;它们的按位或将只是 0x05。)

于 2011-06-23T17:05:01.383 回答