我对这段代码有问题。它总是写着“你在博物馆外面或者再次检查你的位置”祝酒词:你认为问题出在哪里?代码如下:

    x3 = x3 * -1; //for example is 187
    y3 = y3 * -1;//for example is 698

    ImageView img = (ImageView) findViewById(R.id.imageView1);

    if(((x3 <= 150) && (x3 >= 170)) && ((y3 <= 680) && (y3 >= 725))){
        img.setImageResource(R.drawable.map_1_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 1", Toast.LENGTH_LONG).show();
        currentSection = "sect_1";
    }else if(((x3 <= 170) && (x3 >= 195)) && ((y3 <= 690) && (y3 >= 715))){
        img.setImageResource(R.drawable.map_2_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 2", Toast.LENGTH_LONG).show(); //this suppost to be the output
        currentSection = "sect_2";
    }else if(((x3 <= 200) && (x3 >= 230)) && ((y3 <= 680) && (y3 >= 720))){
        img.setImageResource(R.drawable.map_3_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 3", Toast.LENGTH_LONG).show();
        currentSection = "sect_3";
    }else if(((x3 <= 190) && (x3 >= 220)) && ((y3 <= 675) && (y3 >= 710))){
        img.setImageResource(R.drawable.map_4_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 4", Toast.LENGTH_LONG).show();
        currentSection = "sect_4";
    }else if(((x3 <= 175) && (x3 >= 219)) && ((y3 <= 710) && (y3 >= 745))){
        img.setImageResource(R.drawable.map_5_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 5", Toast.LENGTH_LONG).show();
        currentSection = "sect_5";
    }else if(((x3 <= 155) && (x3 >= 165)) && ((y3 <= 715) && (y3 >= 735))){
        img.setImageResource(R.drawable.map_6_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 6", Toast.LENGTH_LONG).show();
        currentSection = "sect_6";
    }else{
        Toast.makeText(getBaseContext(), "You're outside of the museum or Check your postion again", Toast.LENGTH_LONG).show();
    }

最佳答案

这是不可能的

(x3 <= 150) && (x3 >= 170)


(x3 <= 170) && (x3 >= 195)

x3不能小于或等于150,也不能大于或等于170。我猜你是故意的
(150 <= x3) && (x3 <= 170)


(170 <= x3) && (x3 <= 195)

关于java - <= &&> = Java/Android运算符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14558328/

10-11 08:08