How to read result of bitwise operator OR (|)?

2019-06-11 06:57发布

I would like the confirmation on bitwise operators inside Android XML files. For example this line

android:layout_gravity="center_horizontal|bottom"

How should I read it? Are the rules inherited from Java or Android does its own interpretation of bitwise operators?

Are all bitwise operators supported? If yes, could you show me the example of other operators (link is fine as well)?

Thanks

2条回答
放荡不羁爱自由
2楼-- · 2019-06-11 07:45

The value of android_layout_gravity is parsed by Android code. As documented here, the only recognized operator here is |. I don't believe that interpreting | as bitwise OR operator is part of the spec. (For instance, center_horizontal is 0x05 and right is 0x01; their bitwise OR would just be 0x05.)

查看更多
男人必须洒脱
3楼-- · 2019-06-11 08:02
2|1 = 3
2&1 = 0
3&1 = 1

central_horizontal, bottom are integers so you can use this construction

    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
        }
查看更多
登录 后发表回答