本文主要是介绍android studio gridlayout拼图游戏(一)让图片完整显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在慕课网上看到一个拼图游戏的视频,写了一个程序代码:
public class MainActivity extends AppCompatActivity {private boolean gamestart=false;private boolean isrun=false;private ImageView[][] iv_game_arr=new ImageView[3][5];private GridLayout game;private ImageView nullimg;private GestureDetector gestureDetector;@Override public boolean onTouchEvent(MotionEvent event) {return gestureDetector.onTouchEvent(event);}@Override public boolean dispatchTouchEvent(MotionEvent ev) {gestureDetector.onTouchEvent(ev);return super.dispatchTouchEvent(ev);}@Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);gestureDetector=new GestureDetector(this, new GestureDetector.OnGestureListener() {@Override public boolean onDown(MotionEvent motionEvent) {return false;}@Override public void onShowPress(MotionEvent motionEvent) {}@Override public boolean onSingleTapUp(MotionEvent motionEvent) {return false;}@Override public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {return false;}@Override public void onLongPress(MotionEvent motionEvent) {}@Override public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {int type=getGesture(motionEvent.getX(),motionEvent.getY(),motionEvent1.getX(),motionEvent1.getY());changeGesture(type);return true;}});game=(GridLayout)findViewById(R.id.grid);Bitmap bigm=((BitmapDrawable)getResources().getDrawable(R.drawable.pin)).getBitmap();int tuW=bigm.getWidth()/5;for (i
这篇关于android studio gridlayout拼图游戏(一)让图片完整显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!