安卓记账开发(一):整体 UI 界面布局
今天开始进行记账本的开发。
主要想法表述:
1、与用户界面交互的主要有三个界面,总资金管理,收入界面管理,支出管理。
2、实现登录注册功能,在数据库中不同用户有着不同的数据记录。
其他细节在具体开发中进行实现。
今天实现的几个Activity和Fragment的布局界面设计,没有内部逻辑,简单实现UI界面。
首先,Android Studio为我们提供了一种比较好用的抽屉模板Activity,我们可以使用它方便的实现UI界面的设计。
我们可以直接新建navigation drawer activity来使用这种Activity。
根据这个模板,把抽屉栏样式设定成记账本,如下效果:
预期每一个都是一个功能模块,之后实现Activity的跳转。
之后是主界面的设计,使用3个Fragment完成summary、income和outlay的界面布局。
在content_main.xml中,完成3个fragment的切换。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/layoutContent" tools:showIn="@layout/app_bar_main"> <!--主界面的内容--> <androidx.viewpager.widget.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/navigation"> </androidx.viewpager.widget.ViewPager> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/windowBackground" android:layout_alignParentBottom="true" app:menu="@menu/navigation"> </com.google.android.material.bottomnavigation.BottomNavigationView> </RelativeLayout>
其中navigation是自定义的menu文件。
效果如下
并分别创建SummaryFragment、IncomeFragment和OutlayFragment,对应下方的三个图标。
今天不进行内部逻辑的编写,故主要将前端界面大体描绘了一下,后期再添加细节。
对于收入支出,主要思路是用listView展现出来,但内容来自数据库,故此处只将测试内容编写,之后再改即可。
本次完成了整体上记账本的应用布局及界面设计,后期还会做出很多修改。
上一篇: 智能记账系统:颠覆传统,简化企业财务管理
下一篇: 团队作业 #3:记账软件软件设计
推荐阅读
-
安卓记账开发(一):整体 UI 界面布局
-
Android 开发中 nodpi、xhdpi、hdpi、mdpi、ldpi 的概念 - 术语和概念 屏幕尺寸 屏幕的物理尺寸,基于屏幕的对角线长度(如 2.8 英寸、3.5 英寸)。 简而言之,安卓系统将所有屏幕尺寸简化为三大类:大、普通和小。 程序可以为这三种屏幕尺寸提供三种不同的布局选项,然后系统会以合适的方式将布局选项呈现到相应的屏幕上,这个过程不需要程序员用代码进行干预。 屏幕纵横比 屏幕的物理长度与物理宽度之比。程序只需使用系统提供的资源分类器 long(长)和 notlong(不长),就能为具有特定长宽比的屏幕提供配制材料。 分辨率 屏幕的像素总数。请注意,分辨率并不意味着长宽比,尽管在大多数情况下,分辨率表示为 "宽度 x 长度"。在安卓系统中,程序一般不直接处理分辨率。 密度 根据屏幕分辨率,沿屏幕宽度和长度排列的像素数量。 密度较低的屏幕在长度和宽度方向上的像素都相对较少,而密度较高的屏幕通常会在同一区域内排列很多甚至非常非常多的像素。屏幕的密度非常重要;例如,一个界面元素(如按钮)的长度和宽度以像素为单位,在低密度屏幕上会显得很大,但在高密度屏幕上就会显得很小。 独立于密度的像素(DIP)是指程序用来定义界面元素的抽象意义上的像素。它作为一个与实际密度无关的单位,帮助程序员构建布局方案(界面元素的宽度、高度和位置)。 与密度无关的像素在逻辑上与像素密度为 160 DPI 的屏幕上的像素大小相同,而 160 DPI 是安卓平台默认的显示设备。在运行时,平台会以目标屏幕的密度为基准,"透明 "地处理所有所需的 DIP 缩放操作。要将与密度无关的像素转换为屏幕像素,可以使用一个简单的公式:像素 = DIP * (密度 / 160)。例如,在 240 DPI 的屏幕上,1 个 DIP 等于 1.5 个物理像素。强烈建议使用 DIP 来定义程序界面的布局,因为这样可以确保用户界面在所有分辨率的屏幕上都能正常显示。 为了简化程序员在面对各种分辨率时的麻烦,也为了让各种分辨率的平台都能直接运行这些程序,Android 平台将所有屏幕以密度和分辨率作为分类方式,分别分为三类:- 三大尺寸:大、普通、小;- 三种不同密度:高(hdpi)、中(mdpi)和低(ldpi)。DPI 表示 "每英寸点数",即每英寸的像素数。如果需要,程序可以为不同的屏幕尺寸提供不同的资源(主要是布局),为不同的屏幕密度提供不同的资源(主要是位图)。除此之外,程序无需对屏幕尺寸或密度进行任何额外处理。执行时,平台会根据屏幕本身的尺寸和密度特性自动加载相应的资源,并将其从逻辑像素(DIP,用于定义界面布局)转换为屏幕上的物理像素。