第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

運(yùn)行返回值的問(wèn)題

為啥我點(diǎn)哪個(gè)方塊返回的都是false?代碼比著老師的打的。

正在回答

3 回答

GameData?mNullGameData?=?(GameData)?iv_null_ImageView.getTag();//?空的

http://img1.sycdn.imooc.com//57a2e236000130ca09050306.jpg

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

qq_Dazzlingly_0 提問(wèn)者

非常感謝!
2016-08-04 回復(fù) 有任何疑惑可以回復(fù)我~

代碼貼出來(lái)我看看。

0 回復(fù) 有任何疑惑可以回復(fù)我~

package com.example.yidongpintu;



import com.example.yidongpintu.R;


import java.security.PublicKey;


import android.app.Activity;

import android.app.ActionBar;

import android.app.Fragment;

import android.graphics.Bitmap;

import android.graphics.drawable.BitmapDrawable;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.animation.Animation;

import android.view.animation.Animation.AnimationListener;

import android.view.animation.TranslateAnimation;

import android.view.ViewGroup;

import android.widget.GridLayout;

import android.widget.ImageView;

import android.widget.Toast;

import android.os.Build;


public class MainActivity extends Activity {

//利用二維數(shù)組創(chuàng)建若干個(gè)小方塊

private ImageView[][] iv_game_arr= new ImageView[3][5];

private GridLayout gl_main_game;//游戲主界面

private ImageView iv_null_ImageView;//當(dāng)前空方塊實(shí)例的保存

? ? @Override

? ? protected void onCreate(Bundle savedInstanceState) {

? ? ? ? super.onCreate(savedInstanceState);

? ? ? ? setContentView(R.layout.activity_main);

? ? ? ? Bitmap bigBm=((BitmapDrawable)getResources().getDrawable(R.drawable.ic_game_tu)).getBitmap();

? ? ? ? int tuWandH=bigBm.getWidth()/5;

? ? ? for(int i=0;i<iv_game_arr.length;i++){

? ? ?for(int j=0;j<iv_game_arr[0].length;j++){

? ? ?Bitmap bm = Bitmap.createBitmap(bigBm,j*tuWandH,i*tuWandH,tuWandH,tuWandH);

? ? ?iv_game_arr[i][j] =new ImageView(this);

? ? ?iv_game_arr[i][j].setImageBitmap(bm);//設(shè)置每一個(gè)游戲小方塊的圖案

? ? ?iv_game_arr[i][j].setPadding(2, 2, 2, 2);//設(shè)置方塊之間的間隙

? ? ?iv_game_arr[i][j].setTag(new GameData(i, j, bm));//保定自定義的數(shù)據(jù)

? ? ?iv_game_arr[i][j].setOnClickListener(new OnClickListener() {

? ? ?//設(shè)置監(jiān)聽(tīng)

@Override

public void onClick(View v) {

boolean flag = isHasByNullImageView((ImageView) v);

Toast.makeText(MainActivity.this, "位置關(guān)系是否存在:"+flag ,Toast.LENGTH_SHORT).show();

if(flag){changeDataByImageView((ImageView) v);}

}

});

? ? ?}

? ? ? ?

? ? ? ? }

? ? ? gl_main_game=(GridLayout)findViewById(R.id.gl_main_game);

? ? ? for(int i=0;i<iv_game_arr.length;i++){

? ? ?for(int j=0;j<iv_game_arr[0].length;j++){

? ? ?gl_main_game.addView(iv_game_arr[i][j]);

? ? ?}

? ? }

? ? setNullImageView(iv_game_arr[2][4]);

? ??

}

? ? //利用動(dòng)畫結(jié)束之后,交換兩個(gè)方塊的數(shù)據(jù)

? ? //mImageView點(diǎn)擊的方塊

? ? public void changeDataByImageView(final ImageView mImageView){

//創(chuàng)建一個(gè)動(dòng)畫,設(shè)置好方向,移動(dòng)的距離

? TranslateAnimation translateAnimation=null;

? if(mImageView.getX()>iv_null_ImageView.getX()){//當(dāng)前電機(jī)的方塊在空方塊的下面

?translateAnimation=new TranslateAnimation(0.1f, -mImageView.getWidth(),0.1f,0.1f);}

? else if(mImageView.getX()<iv_null_ImageView.getX()){//在上面

?translateAnimation=new TranslateAnimation(0.1f, mImageView.getWidth(),0.1f,0.1f);}

? else if(mImageView.getY()>iv_null_ImageView.getY()){//在左面

?translateAnimation=new TranslateAnimation(0.1f,0.1f,0.1f,-mImageView.getWidth());}

? else if(mImageView.getY()<iv_null_ImageView.getY()){//在右邊

?translateAnimation=new TranslateAnimation(0.1f,0.1f,0.1f,mImageView.getWidth());}

? ??

? ??

?//設(shè)置動(dòng)畫的時(shí)長(zhǎng)

translateAnimation.setDuration(70);


?//設(shè)置動(dòng)畫之后是否停留

? ? translateAnimation.setFillAfter(true);

?//設(shè)置 動(dòng)畫結(jié)束之后要真正的把數(shù)據(jù)交換了

translateAnimation.setAnimationListener(new AnimationListener(){


?public void onAnimationStart(Animation animation) {

?

?}

public void onAnimationRepeat(Animation animation) {

?

?}

public void onAnimationEnd(Animation animation) {

mImageView.clearAnimation();

GameData mGameData=(GameData)mImageView.getTag();?

iv_null_ImageView.setImageBitmap(mGameData.bm);

GameData mNullGameData=(GameData)iv_null_ImageView.getTag();

mNullGameData.bm = mGameData.bm;

? ? mNullGameData.p_x=mGameData.p_x;

? ? mNullGameData.p_y=mGameData.p_y;

? ? setNullImageView(mImageView);//設(shè)置當(dāng)前點(diǎn)擊的為空方塊

}


});

//執(zhí)行動(dòng)畫

mImageView.startAnimation(translateAnimation);

}

? ? // ?設(shè)置最后一個(gè)方塊為空

private void setNullImageView(ImageView mImageView) {

mImageView.setImageBitmap(null);

iv_null_ImageView=mImageView;

}

/*

* 判斷當(dāng)前點(diǎn)擊的方塊,是否與空方塊的位置關(guān)系是相鄰關(guān)系

* true是相鄰,false是不相鄰

* mImageView為所點(diǎn)擊的方塊*/

public boolean isHasByNullImageView(ImageView mImageView){

//分別獲取當(dāng)前空方塊的位置與點(diǎn)擊方塊的位置,通過(guò)x,y兩邊都差1的方式判斷

GameData mNullGameData=(GameData)mImageView.getTag();//空的

GameData mGameData=(GameData)mImageView.getTag();//當(dāng)前點(diǎn)擊的

if(mNullGameData.y==mGameData.y&&mNullGameData.x==mGameData.x+1)

{/*當(dāng)時(shí)點(diǎn)擊的方塊在空方塊的上邊*/

return true;}

else if (mNullGameData.y==mGameData.y&&mNullGameData.x==mGameData.x-1)

{/*下邊*/

return true;}

else if (mNullGameData.y==mGameData.y+1&&mNullGameData.x==mGameData.x)

{/* 左邊*/

return true;}

else if (mNullGameData.y==mGameData.y-1&&mNullGameData.x==mGameData.x)

{/* 右邊*/

return true;}

return false;

}/*每個(gè)游戲上要綁定的數(shù)據(jù)*/

class GameData{

/*每個(gè)小方塊的實(shí)際位置x,y

* 每個(gè)小方塊的圖片位置p_x,p_y*/

public int x=0;

public int y=0;

public ?Bitmap bm;

public int p_x=0;

public int p_y=0;

public GameData(int x, int y,Bitmap bm ) {

super();

this.x = x;

this.y = y;

this.bm = bm;

this.p_x = x;

this.p_y = y;

}

?

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

運(yùn)行返回值的問(wèn)題

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)