Java 未检测到ImageView相交

Java 未检测到ImageView相交,java,android,android-imageview,rect,intersect,Java,Android,Android Imageview,Rect,Intersect,我正在尝试两种不同的方法来检测交叉口,但两种方法都不起作用。我遵循其他线程,但出于某种原因,这两种方法都不起作用!有人能帮忙吗?这是我第一次尝试 Activity.java: import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.AppCompatActiv

我正在尝试两种不同的方法来检测交叉口,但两种方法都不起作用。我遵循其他线程,但出于某种原因,这两种方法都不起作用!有人能帮忙吗?这是我第一次尝试

Activity.java:

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.graphics.Rect;


public class gameScreen extends AppCompatActivity {

    //Global variable declarations
    Button quit_button;
    Button pause_button;
    String aviChoice;
    String aviMF_choice;
    ImageView aviCharacter, aviBase;
    Handler handler0 = new Handler();
    Handler handler1 = new Handler();
    Handler handler2 = new Handler();
    Handler handler3 = new Handler();
    float aviHeightLimit, jumpDeltaY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gamescreen);

        Bundle extras = getIntent().getExtras();
        if(extras != null)
        {
            aviChoice = extras.getString(aviMF_choice);
        }

        jumpDeltaY = 10;
        aviCharacter = (ImageView) findViewById(R.id.aviCharacter_img);
        final Rect aviCharacterRect = new Rect();
        aviCharacter.getHitRect(aviCharacterRect);
        aviBase = (ImageView) findViewById(R.id.aviBase_img);
        final Rect aviBaseRect = new Rect();
        aviBase.getHitRect(aviBaseRect);

        aviHeightLimit = aviBase.getY() - 150;
        aviCharacter.setY(aviBase.getY() - 25);

        aviBase.setBackgroundResource(R.drawable.bouncebase);
        if(aviChoice.equals("male"))
        {
            aviCharacter.setBackgroundResource(R.drawable.avimstandard);
        }
        if(aviChoice.equals("female"))
        {
            aviCharacter.setBackgroundResource(R.drawable.avifstandard);
        }


        //Runnables ================================================================================
        Runnable aviJumping = new Runnable() {
            @Override
            public void run() {
                if(aviCharacter.getY() < aviHeightLimit)
                {
                    jumpDeltaY = -jumpDeltaY;
                }
                if(Rect.intersects(aviBaseRect, aviCharacterRect))
                {
                    Log.i("test", "intersection detected old");
                    jumpDeltaY = -jumpDeltaY;
                }
                if(aviCharacterRect.intersect(aviBaseRect))
                {
                    Log.i("test", "intersection detected new");
                    jumpDeltaY = -jumpDeltaY;
                }
                aviCharacter.setY(aviCharacter.getY() + jumpDeltaY);
                Log.i("test", ""+Rect.intersects(aviCharacterRect,aviBaseRect));
                handler0.postDelayed(this, 100);
            }
        };
        handler0.postDelayed(aviJumping,100);
        //==========================================================================================
    }
导入android.content.Intent;
导入android.graphics.Typeface;
导入android.os.Bundle;
导入android.os.Handler;
导入android.support.v7.app.AppActivity;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.ImageView;
导入android.graphics.Rect;
公共类gameScreen扩展AppCompative活动{
//全局变量声明
按钮退出按钮;
按钮暂停按钮;
字符串选择;
字符串aviMF_选择;
ImageView-avibacter,aviBase;
Handler handler0=新的Handler();
Handler handler1=新的Handler();
Handler handler2=新的Handler();
Handler handler3=新的Handler();
浮动高度限制,jumpDeltaY;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gamescreen);
Bundle extras=getIntent().getExtras();
如果(附加值!=null)
{
avioice=extras.getString(aviMF_-choice);
}
金三角=10;
aviCharacter=(ImageView)findViewById(R.id.aviCharacter\u img);
final Rect aviCharacterRect=新Rect();
aviCharacter.getHitRect(aviCharacterRect);
aviBase=(ImageView)findViewById(R.id.aviBase\u img);
final Rect aviBaseRect=新Rect();
aviBase.getHitRect(aviBaseRect);
aviHeightLimit=aviBase.getY()-150;
aviCharacter.setY(aviBase.getY()-25);
aviBase.setBackgroundResource(R.drawable.bouncebase);
if(avioice.equals(“男性”))
{
aviCharacter.setBackgroundResource(R.drawable.AvimsStandard);
}
if(avioice.equals(“女性”))
{
aviCharacter.setBackgroundResource(R.drawable.avifstandard);
}
//可运行================================================================================
Runnable=新的Runnable(){
@凌驾
公开募捐{
if(aviCharacter.getY()