我也来开发2048之主界面设计

简介: 我的开发惯例,先把界面设计出来,看过我前面博客的朋友应该知道了。接上次,今天的主要目的是设计界面,主界面其实比较简单了,我们先上图:层次并不复杂,难点在于中间游戏面板的设计,这个我们留着下次详细讲咯主布局是一个LinearLayout,这个很容易看出来,主要是Button样式的改造,我...

我的开发惯例,先把界面设计出来,看过我前面博客的朋友应该知道了。


接上次,今天的主要目的是设计界面,主界面其实比较简单了,我们先上图:


层次并不复杂,难点在于中间游戏面板的设计,这个我们留着下次详细讲咯

主布局是一个LinearLayout,这个很容易看出来,主要是Button样式的改造,我使用了一个自定义shape加selector来实现,这几个Button主要就是shape颜色的不同

下面显示一个Shape来示例:

<?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="10dip" />

            <!-- padding:Button里面的文字与Button边界的间隔 -->
            <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
        </shape></item>
    <item><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

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

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

</selector>

下面就是主布局的全部代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="3dp" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="3dp"
                android:background="@drawable/orange_button"
                android:text="2048"
                android:textSize="50sp" />
        </LinearLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/score_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/gray_button"
                android:gravity="center"
                android:text="Scroe"
                android:textSize="25sp" />

            <TextView
                android:id="@+id/scroe"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/score_title"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/light_orange_button"
                android:gravity="center"
                android:text="10000"
                android:textSize="15sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/record_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/gray_button"
                android:gravity="center"
                android:text="Record"
                android:textSize="25sp" />

            <TextView
                android:id="@+id/record"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/record_title"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/light_orange_button"
                android:gravity="center"
                android:text="20000"
                android:textSize="15sp" />
        </RelativeLayout>
    </LinearLayout>

    <com.xys.game2048.view.GameView
        android:id="@+id/gameView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </com.xys.game2048.view.GameView>

    <LinearLayout
        style="?android:attr/buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="3dp" >

        <Button
            android:id="@+id/btn_revert"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/blue_button"
            android:text="Revert" />

        <Button
            android:id="@+id/btn_restart"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/blue_button"
            android:text="Restart" />

        <Button
            android:id="@+id/btn_option"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/blue_button"
            android:text="Options" />
    </LinearLayout>

</LinearLayout>

相信大家不用多少介绍也能看懂了,我就不多介绍了。


游戏中要实现的功能主要有以下几点:

1、主标题上显示应该达到的目标,如果你没达到过2048则显示2048,如果超过了,则显示下一个目标,如4096

2、Score记录当前游戏分数,Record记录历史最高记录

3、Revert用于撤销上次的移动,玩过2048的肯定深有感触,一不小心移错一步,就掉坑里爬不出来了,但是现在市面上的2048基本上都没这个功能,所以这次准备加上这个功能

4、Options,这个是国际惯例了


以上,今天的基本就是这样。

PS 需要源码的朋友可以留言,完善后会发布所有源码


目录
打赏
0
0
0
0
16
分享
相关文章
在Mockplus中使用收藏功能,提高工作效率
在Mockplus中,对于你经常要使用的组件、页面或者图片素材,你可以把它们收藏起来,以便下次重复使用,提高工作效率。 现在我们来看看如果收藏一个页面: 1 在当前页面空白处,鼠标右键菜单,选择“把本页收藏为模版”; 2 此时,工作区左侧的页面收藏面板会出现,当前页面已经被收藏; 3 在收藏面板的列表中,选择刚才收藏的页面,直接拖动到工作区。
649 0
点晴OA系统:用户体验至上,操作简单易上手
在数字化转型的浪潮中,企业选择办公自动化(OA)系统时,除了关注功能强大与否,更看重系统的用户体验。一个操作复杂、学习成本高的系统,不仅会降低员工的工作效率,还可能影响企业的整体运营。点晴OA系统以“用户体验至上”为核心理念,致力于打造操作简单、易上手的办公平台,帮助企业快速实现高效办公。
26 1
《社交网站界面设计(原书第2版)》——2.5 严格 VS. 灵活的分类法
本节书摘来自华章计算机《社交网站界面设计(原书第2版)》一书中的第2章,第2.5节,作者:(美)克里斯蒂安·克鲁姆里什(Christian Crumlish),艾琳·马洛恩(Erin Malone)著, 更多章节内容可以访问云栖社区“华章计算机”公众号查看。
1024 0
UI设计师必备的五款界面设计工具
在前几篇文章中,我们分享了一些最受欢迎的原型设计工具,今天我们来谈谈界面设计工具。工具的重要性对于设计师来讲不言而喻。任何想法都需要借助工具来实现。想要成为一名出色的UI设计师,你需要多掌握一些技能,才能增强自身竞争力。
3050 0
设计团队协作办公软件评测:哪 6 款最值得设计师选用?
在软件设计开发领域,高效的团队协作至关重要。本文推荐6款可视化团队协作软件,旨在帮助偏好计划与秩序的J人群体提升协作效率。包括国内的板栗看板及国外的Trello、Asana、Jira、Monday.com和Basecamp,它们各具特色,如板栗看板的简洁直观、Trello的高度可定制化、Asana的智能任务管理、Jira的专业开发支持、Monday.com的多样化视图和Basecamp的简洁高效,均能有效支持不同规模和需求的团队,优化工作流程,确保项目顺利推进。
56 6
UI 设计团队协作有妙招!哪类办公软件能拔高效率?
本文介绍了6款适合游戏原画团队的高效协作办公软件,包括板栗看板及5款国外软件。这些软件通过可视化任务管理、灵活的任务分配、强大的文件管理和版本控制、便捷的沟通机制等功能,帮助团队提升创作效率,促进成员间无缝协作,适应不同规模和需求的游戏原画项目。
74 15

相关实验场景

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等