Android拼图游戏开发全纪录1

简介: 今天我们继续来讲解Android拼图游戏全纪录的第二篇,今天要完成的任务比较简单:界面布局和资源文件 1资源文件: 我们在开发一个项目的时候,首先要定下这个App的基调,是小清新呢还是重口味,所以我们需要定义一些颜色、style等 首先...

今天我们继续来讲解Android拼图游戏全纪录的第二篇,今天要完成的任务比较简单:界面布局和资源文件


1资源文件:

我们在开发一个项目的时候,首先要定下这个App的基调,是小清新呢还是重口味,所以我们需要定义一些颜色、style等

首先是颜色等:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="app_bg">#000000</color>
    
    <color name="title_text">#FFFFFF</color>
    
    <color name="record_title_bg">#F56A47</color>
    <color name="record_title_text">#FFFFFF</color>
    <color name="record_title_text_dark">#727272</color>
    
    <color name="main_bg">#3EC5FF</color>
    <color name="main_text">#FFFFFF</color>
    
    <color name="setting_reg_bg">#A2A2A2</color>
    <color name="setting_text_light">#C3C3C3</color>
    <color name="setting_text_dark">#111111</color>
    
    <color name="tv_click">#33444444</color>
</resources>

以上就定义好了我们这个App的小清新的风格

然后是字符串资源,这个随意吧

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">XPuzzle</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="puzzle_main_type">选择难度:</string>
    <string name="puzzle_main_steps">步数:</string>
    <string name="puzzle_main_img">原        图</string>
    <string name="puzzle_main_reset">重        置</string>
    <string name="puzzle_main_back">返        回</string>
    <string name="puzzle_main_time">时间:</string>
    <string name="puzzle_main_type_selected">2 X 2</string>
    <string name="puzzle_main_record">查看记录</string>
    <string name="puzzle_main_more">了解更多</string>

</resources>

接下来是自定义的一个带Selector的Shape,这样Button使用这个背景后,就比较配合小清新的风格了

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"><shape android:shape="rectangle">

            <!-- 填充的颜色 -->
            <solid android:color="#33444444" />
            <!-- 设置按钮的四个角为弧形 -->
            <!-- android:radius 弧形的半径 -->
            <corners android:radius="5dip" />

            <!-- padding:Button里面的文字与Button边界的间隔 -->
            <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
        </shape></item>
    <item><shape android:shape="rectangle">

            <!-- 填充的颜色 -->
            <solid android:color="@color/title_text" />
            <!-- 设置按钮的四个角为弧形 -->
            <!-- android:radius 弧形的半径 -->
            <corners android:radius="5dip" />

            <!-- padding:Button里面的文字与Button边界的间隔 -->
            <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
        </shape></item>

</selector>

这个就是我们在前面图中看见的Button了,是不是很好看啊

嗯 还有个TextView的selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/tv_click" android:state_pressed="true"></item>
    <item android:drawable="@android:color/transparent"></item>

</selector>

下面我们就要开始实现我们的界面了:

首先是首页界面:


布局比较简单,相信大家都看得懂

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/main_bg" >

    <LinearLayout
        android:id="@+id/ll_puzzle_main_spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_margin="10dip" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/puzzle_main_type"
            android:textColor="@color/main_text"
            android:textSize="@dimen/text_title" />

        <TextView
            android:id="@+id/tv_puzzle_main_type_selected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/textview_click"
            android:text="@string/puzzle_main_type_selected"
            android:textColor="@color/main_text"
            android:textSize="@dimen/text_title" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_xpuzzle_main_functions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/gv_xpuzzle_main_pic_list"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:layout_alignRight="@+id/gv_xpuzzle_main_pic_list"
        android:layout_margin="@dimen/padding" >

        <Button
            android:id="@+id/btn_puzzle_main_record"
            style="@style/btn_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/padding"
            android:background="@drawable/white_button"
            android:text="@string/puzzle_main_record" />

        <Button
            android:id="@+id/btn_puzzle_main_setting"
            style="@style/btn_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/padding"
            android:background="@drawable/white_button"
            android:text="@string/puzzle_main_more" />
    </LinearLayout>

    <GridView
        android:id="@+id/gv_xpuzzle_main_pic_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/ll_xpuzzle_main_functions"
        android:layout_below="@id/ll_puzzle_main_spinner"
        android:layout_centerHorizontal="true"
        android:layout_margin="@dimen/padding"
        android:gravity="center_horizontal"
        android:horizontalSpacing="@dimen/padding"
        android:numColumns="4"
        android:padding="@dimen/padding"
        android:verticalSpacing="@dimen/padding" >
    </GridView>

</RelativeLayout>

这就OK了。

里面的选择难度是一个popupwindow,所以还有个布局文件

这个。。so easy了

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tv_main_type_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        android:text="2x2"
        android:textColor="@color/main_text"
        android:textSize="@dimen/text_title_sub" />

    <TextView
        android:id="@+id/tv_main_type_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        android:text="3x3"
        android:textColor="@color/main_text"
        android:textSize="@dimen/text_title_sub" />

    <TextView
        android:id="@+id/tv_main_type_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="4x4"
        android:textColor="@color/main_text"
        android:textSize="@dimen/text_title_sub" />

</LinearLayout>

最后是拼图的布局界面:如下图


就是这样啦,其实界面也很简单

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_puzzle_main_main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/main_bg" >

    <LinearLayout
        android:id="@+id/ll_puzzle_main_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/padding"
        android:gravity="center_horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/puzzle_main_steps"
            android:textColor="@color/title_text"
            android:textSize="@dimen/text_title" />

        <TextView
            android:id="@+id/tv_puzzle_main_counts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:paddingRight="50dip"
            android:text="1"
            android:textColor="@color/title_text"
            android:textSize="@dimen/text_title" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/puzzle_main_time"
            android:textColor="@color/title_text"
            android:textSize="@dimen/text_title" />

        <TextView
            android:id="@+id/tv_puzzle_main_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/title_text"
            android:textSize="@dimen/text_title" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_puzzle_main_btns"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_margin="@dimen/padding" >

        <Button
            android:id="@+id/btn_puzzle_main_img"
            style="@style/btn_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/padding"
            android:background="@drawable/white_button"
            android:text="@string/puzzle_main_img" />

        <Button
            android:id="@+id/btn_puzzle_main_restart"
            style="@style/btn_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/padding"
            android:background="@drawable/white_button"
            android:text="@string/puzzle_main_reset" />

        <Button
            android:id="@+id/btn_puzzle_main_back"
            style="@style/btn_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/padding"
            android:background="@drawable/white_button"
            android:text="@string/puzzle_main_back" />
    </LinearLayout>

    <GridView
        android:id="@+id/gv_puzzle_main_detail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/ll_puzzle_main_btns"
        android:layout_below="@id/ll_puzzle_main_spinner"
        android:layout_centerInParent="true"
        android:layout_margin="@dimen/padding" >
    </GridView>

</RelativeLayout>

好了,今天的东西都是些准备工作,所以比较简单。
目录
相关文章
|
4月前
|
移动开发 前端开发 Android开发
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
595 12
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
4月前
|
移动开发 JavaScript 应用服务中间件
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
513 5
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
4月前
|
移动开发 Rust JavaScript
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
899 4
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
5月前
|
开发工具 Android开发
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
684 11
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
|
4月前
|
移动开发 Android开发
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
260 0
|
5月前
|
Java 开发工具 Maven
【01】完整的安卓二次商业实战-详细的初级步骤同步项目和gradle配置以及开发思路-优雅草伊凡
【01】完整的安卓二次商业实战-详细的初级步骤同步项目和gradle配置以及开发思路-优雅草伊凡
463 6
|
7月前
|
安全 数据库 Android开发
在Android开发中实现两个Intent跳转及数据交换的方法
总结上述内容,在Android开发中,Intent不仅是活动跳转的桥梁,也是两个活动之间进行数据交换的媒介。运用Intent传递数据时需注意数据类型、传输大小限制以及安全性问题的处理,以确保应用的健壯性和安全性。
510 11
|
11月前
|
JavaScript Linux 网络安全
Termux安卓终端美化与开发实战:从下载到插件优化,小白也能玩转Linux
Termux是一款安卓平台上的开源终端模拟器,支持apt包管理、SSH连接及Python/Node.js/C++开发环境搭建,被誉为“手机上的Linux系统”。其特点包括零ROOT权限、跨平台开发和强大扩展性。本文详细介绍其安装准备、基础与高级环境配置、必备插件推荐、常见问题解决方法以及延伸学习资源,帮助用户充分利用Termux进行开发与学习。适用于Android 7+设备,原创内容转载请注明来源。
3129 77
|
7月前
|
移动开发 Java 编译器
Kotlin与Jetpack Compose:Android开发生态的演进与架构思考
本文从资深Android工程师视角深入分析Kotlin与Jetpack Compose在Android系统中的技术定位。Kotlin通过空安全、协程等特性解决了Java在移动开发中的痛点,成为Android官方首选语言。Jetpack Compose则引入声明式UI范式,通过重组机制实现高效UI更新。两者结合不仅提升开发效率,更为跨平台战略和现代架构模式提供技术基础,代表了Android开发生态的根本性演进。
326 0
|
8月前
|
安全 Java Android开发
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
386 0
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡

热门文章

最新文章