安卓手机拼图游戏(简单易懂,附源码和安装包apk)

献给热爱编程的朋友,安装包下载地址(提取码:4g3g): https://pan.baidu.com/s/14-BaDBN9MEBR3DJTNZqn3A
源代码下载地址: https://gitee.com/landzy/PinTuGame-share.git


一、应用介绍

这是一款用安卓studio开发的拼图游戏,通过点击空白区域相邻的图片进行移动,直至还原成示例图片即为游戏成功。
游戏界面如下:


  • 游戏主界面:
    游戏主界面

  • 游戏成功界面

游戏成功界面


二、源代码

1.布局文件(activity_main.xml)

通过线性布局的嵌套,实现九宫格的排版,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_marginTop="20dp"
        android:background="@color/purple_200"
        android:orientation="vertical"
        android:padding="2dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:id="@+id/line1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:padding="0.1dp">

            <ImageButton
                android:id="@+id/imageButton_00"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="0.1dp"
                android:scaleType="centerCrop" />

            <ImageButton
                android:id="@+id/imageButton_01"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="0.1dp"
                android:scaleType="centerCrop" />

            <ImageButton
                android:id="@+id/imageButton_02"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="0.1dp"
                android:scaleType="centerCrop" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/line2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:padding="0.1dp">

            <ImageButton
                android:id="@+id/imageButton_03"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="0.1dp"
                android:scaleType="centerCrop" />

            <ImageButton
                android:id="@+id/imageButton_04
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值