安卓软件设计方案 第1篇
项目的根目录中包含一个名称为的文件,称为项目清单文件。清单文件向Android系统提供必要的项目全局信息。
清单文件的主要功能:
(1)命名软件包名称,做为应用的唯一标识符。
(2)描述应用的各个组件,包括构成应用的Activity、服务、广播接收器和内容提供程序等。
(3)确定用户权限,如互联网访问权限、照相机使用权限、开放联系人读取权限等。
本项目需要访问网络,需要使用照相机拍摄照片,需要外部存储器的读取权限,所以需要在清单文件中添加如下权限配置语句:
本项目的Web服务器采用HTTP协议访问模式,故需要在application节点中添加语句android:usesCleartextTraffic=_true_,允许通过HTTP协议收发数据。
安卓软件设计方案 第2篇
android:layout_width=_match_parent_
android:layout_height=_match_parent_
app:defaultNavHost=_true_
app:navGraph=_@navigation/nav_graph_ />
程序段P完成OverviewFragment的布局文件fragment_overview的定义。
安卓软件设计方案 第3篇
ViewModel组件以Activity 或 Fragment 实例生命周期的方式存储和管理界面显示的相关数据。ViewModel组件在屏幕旋转、Activity或Fragment切换到后台的情况下仍会继续管理和维护界面数据。
图6.17显示Activity发生屏幕旋转事件时,生命周期中的状态变化与ViewModel的数据管理关系。
图 ViewModel组件的生命周期
不难看出,ViewModel组件的生命周期与关联的Activity是同步的。当Activity发生屏幕旋转,Activity进入onPause、onStop、onDestroy状态时,ViewModel仍然管理和维持界面数据。只有在Activity进入结束阶段的onDestroy状态后,ViewModel才会释放数据,结束生命周期。
图6.17描述的ViewModel与Activity的关系,同样适用于Fragment生命周期内的界面数据管理。
ViewModel实时更新界面数据的逻辑如图6.18所示。
图 使用ViewModel加载数据
界面窗体控制器(Activity或者Fragment)通过ViewModelProvider关联到ViewModel组件,ViewModel组件通过LiveData对象管理数据,也可以通过Room访问数据库中的数据。当ViewModel管理的数据发生变化时,只要界面控制器处于活动状态,界面控制器就能实时检测到变化的数据,并自动将其实时更新到界面上。
安卓软件设计方案 第4篇
在项目初始结构(图6.3)基础上,选择根目录appletree,右击鼠标,执行命令New─Package,依次创建五个子模块,分别是network(访问网络)、overview(主页)、recognition(识别)、notifications(资讯)、detail(详情),如图6.4所示。
图6.4 项目子模块结构
遵照图6.4的提示,依次完成各个子模块的分层定义,程序名称及其功能定义如表6.1所示。
表6.1 程序名称及功能描述
模块名
程序名
功能描述
对应的布局文件
overview
OverviewFragment
主页面的控制逻辑
fragment_overview
grid_view_item
OverviewViewModel
视图数据控制逻辑
PhotoGridAdapter
主页数据绑定适配器
detail
DetailFragment
详情页面控制逻辑
fragment_detail
DetailViewModel
视图数据控制逻辑
DetailViewModelFactory
详情页面视图数据绑定
network
AppleApiService
访问网络,图片上传和下载
AppleProperty
苹果树实体类,定义相关属性
AppleResult
服务器返回的实体对象
recognition
RecognitionFragment
图像识别的界面控制逻辑
fragment_recognition
RecognitionViewModel
视图数据控制逻辑
notifications
NotificationsFragment
新闻资讯的界面控制逻辑
fragment_notifications
NotificationsViewModel
视图数据控制逻辑
主模块
BindingAdapters
全局性数据绑定适配器
MainActivity
主程序
activity_main
Fragment的创建方法与步骤,以创建OverviewFragment为例,选择子包overview,右击鼠标,执行命令New─Fragment─Fragment(Blank),设置名称等相关参数,如图6.5所示,创建OverviewFragment类的同时,会同时创建与之对应的布局文件fragment_overview。
图 创建Fragment
其他类的创建方法与步骤,以创建OverviewViewModel为例。选择子包overview,右击鼠标,执行命令New─Kotlin Class/File,设置名称参数,如图6.6所示。
图 创建Kotlin Class/File程序文件
安卓软件设计方案 第5篇
fun bindImage(imgView: ImageView, imgUrl: String?) {
imgUrl?.let {
val imgUri = ().buildUpon().scheme(_http_).build()
()
.load(imgUri)
.apply(RequestOptions()
.placeholder()
.error())
.into(imgView)
}
安卓软件设计方案 第6篇
Android Studio选择Gradle作为项目的构建部署工具,管理各种依赖关系。Gradle用于项目资源与源代码编译,然后将它们打包成可供测试、部署、签署和分发的APK。项目中包含两个名称为的配置文件,如图所示,一个作用于项目的全局依赖配置,称为项目依赖;一个作用于模块的依赖配置,称为模块依赖。
图 项目依赖与模块依赖文件
①与②的文件名称均为,但是作用域和功能逻辑是不同的。前者是整个工程项目的构建脚本,后者是当前模块App的构建脚本。
通常采用如图所示的三段式结构语法表示依赖项,依次为:颁发依赖库的组织机构或库路径、库的名称和版本号。
图 依赖库的三段式结构表示
在项目依赖文件的dependencies节点中,添加依赖项:
def nav_version = __
classpath _:$nav_version_
同步项目依赖文件,同步或重构依赖关系。
在模块依赖文件的dependencies节点中,添加依赖项,如程序段所示,粗体表示在原有基础上新增的依赖语句。
安卓软件设计方案 第7篇
底部导航条的三个按钮需要三个定制图标。用户访问网络获取数据时,为了表示网络的状态,也需要三个定制图标。这些图标资源,存放于res下面的drawable节点中。文件列表如图6.12所示。
图6.12 图标资源文件列表
各个图像资源文件含义如表6.2所示。
表6.2 图像资源文件解析
文件名称
功能描述
对应的图标
数据无法获取的状态提示
禁止网络访问的状态提示
正在下载数据的状态提示
菜单项“首页”的图标提示
菜单项“识别”的图标提示
菜单项“资讯”的图标提示
从本章课件中找到上述图标资源文件,将其直接拷贝到项目的drawable节点下即可。
为了让App的图标拥有个性化设计元素,用户可以用自己的矢量图替换Android Studio为项目创建的默认图标。
从本章课件中找到名称为的图片,如图6.13所示。
图6.13 用于定制App图标的图片
安卓软件设计方案 第8篇
tools:itemCount=_8_
tools:listitem=_@layout/grid_view_item_ />
android:id=_@+id/status_image_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
app:layout_constraintBottom_toBottomOf=_parent_
app:layout_constraintLeft_toLeftOf=_parent_
app:layout_constraintRight_toRightOf=_parent_
app:layout_constraintTop_toTopOf=_parent_
app:appleApiStatus=_@{}_ />
程序段P完成DetailFragment的布局文件fragment_detail的定义。
安卓软件设计方案 第9篇
图6.1 选择项目模板
图6.2 定义项目名称等初始参数
用公司域名的反向形式做为包的名称是一种惯例。之所以将API限定为21版本,是因为项目中调用了CameraX的相关API,CameraX需要API 21以上的版本支持。项目初始结构如图6.3所示。
图6.3 项目初始结构
运用真机或者模拟器运行测试项目,屏幕首页显示“Hello World”。
安卓软件设计方案 第10篇
app:layout_constraintEnd_toEndOf=_parent_
app:layout_constraintStart_toStartOf=_parent_
app:layout_constraintTop_toTopOf=_parent_
app:srcCompat=_@drawable/ic_launcher_background_ />
android:id=_@+id/txtHint_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginTop=_10dp_
android:text=_采集图像_
android:textColor=_@color/black_
android:textSize=_18sp_
app:layout_constraintEnd_toEndOf=_parent_
app:layout_constraintStart_toStartOf=_parent_
app:layout_constraintTop_toBottomOf=_@+id/imageView_ />
android:id=_@+id/txtHealthy_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginStart=_20dp_
android:layout_marginTop=_10dp_
android:text=__
android:textColor=_@color/black_
android:textSize=_20sp_
app:layout_constraintStart_toStartOf=_parent_
app:layout_constraintTop_toBottomOf=_@+id/txtHint_ />
android:id=_@+id/txtMultiple_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginStart=_20dp_
android:layout_marginTop=_10dp_
android:text=__
android:textColor=_@color/black_
android:textSize=_20sp_
app:layout_constraintStart_toStartOf=_parent_
app:layout_constraintTop_toBottomOf=_@+id/txtHealthy_ />
android:id=_@+id/txtRust_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginStart=_20dp_
android:layout_marginTop=_10dp_
android:text=__
android:textColor=_@color/black_
android:textSize=_20sp_
app:layout_constraintStart_toStartOf=_parent_
app:layout_constraintTop_toBottomOf=_@+id/txtMultiple_ />
android:id=_@+id/txtScab_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginStart=_20dp_
android:layout_marginTop=_10dp_
android:text=__
android:textColor=_@color/black_
android:textSize=_20sp_
app:layout_constraintStart_toStartOf=_parent_
app:layout_constraintTop_toBottomOf=_@+id/txtRust_ />
android:id=_@+id/btnCapture_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginBottom=_?actionBarSize_
android:text=_拍照识别_
android:textSize=_24sp_
app:layout_constraintBottom_toBottomOf=_parent_
app:layout_constraintStart_toStartOf=_parent_ />
android:id=_@+id/btnLoadPicture_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginBottom=_?actionBarSize_
android:text=_图库识别_
android:textSize=_24sp_
app:layout_constraintBottom_toBottomOf=_parent_
app:layout_constraintEnd_toEndOf=_parent_ />
程序段P完成NotificationsFragment的布局文件fragment_notifications的定义。
安卓软件设计方案 第11篇
为便于用户操作,屏幕底部定义了一个导航条,包含“首页”、“识别”和“资讯”三个子菜单项,将其定义为菜单资源文件bottom_nav_menu。另外,将一些操作频率不高的菜单项封装到more_menu文件中,显示为屏幕右上角的下拉菜单。
右击项目的res资源节点,在快捷菜单中选择New─Android Resource File命令,弹出如图6.10所示的对话框,设置菜单文件名称为bottom_nav_menu,设置资源类型为Menu,单击OK按钮。
图6.10 创建底部导航菜单
程序段P完成屏幕底部导航菜单bottom_nav_menu的定义。
安卓软件设计方案 第12篇
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长! 8)]
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长! [外链图片转存中…(img-pnt5c9pv-1712725442118)]
安卓软件设计方案 第13篇
tools:layout=_@layout/fragment_overview_>
android:id=_@+id/action_showDetail_
app:destination=_@id/detailFragment_ />
android:id=_@+id/detailFragment_
android:name=__
android:label=_@string/title_detail_
tools:layout=_@layout/fragment_detail_>
android:name=_selectedProperty_
app:argType=__
/>
android:id=_@+id/navigation_recognition_
android:name=__
android:label=_@string/title_recognition_
tools:layout=_@layout/fragment_recognition_ />
android:id=_@+id/navigation_notifications_
android:name=__
android:label=_@string/title_notifications_
tools:layout=_@layout/fragment_notifications_ />
完成导航文件nav_graph的定义后,在res节点下面,会生成名称为navigation的节点,该节点中包含定义的导航文件。
安卓软件设计方案 第14篇
tools:src=_@tools:sample/avatars_ />
android:id=_@+id/apple_id_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginTop=_20dp_
tools:text=_@{}_
android:textColor=_#de000000_
android:textSize=_20sp_
app:layout_constraintLeft_toLeftOf=_parent_
app:layout_constraintTop_toBottomOf=_@id/main_photo_image_ />
android:id=_@+id/apple_name_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginTop=_15dp_
tools:text=_@{}_
android:textColor=_#de000000_
android:textSize=_20sp_
app:layout_constraintLeft_toLeftOf=_parent_
app:layout_constraintTop_toBottomOf=_@id/apple_id_ />
android:id=_@+id/apple_feature_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginTop=_15dp_
android:paddingTop=_10dp_
tools:text=_@{}_
android:textColor=_#de000000_
android:textSize=_20sp_
android:lineSpacingMultiplier=__
app:layout_constraintLeft_toLeftOf=_parent_
app:layout_constraintTop_toBottomOf=_@id/apple_name_ />
android:id=_@+id/apple_regular_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginTop=_15dp_
android:paddingTop=_10dp_
tools:text=_@{}_
android:textColor=_#de000000_
android:textSize=_20sp_
android:lineSpacingMultiplier=__
app:layout_constraintLeft_toLeftOf=_parent_
app:layout_constraintTop_toBottomOf=_@id/apple_feature_ />
android:id=_@+id/apple_cure_
android:layout_width=_wrap_content_
android:layout_height=_wrap_content_
android:layout_marginTop=_15dp_
android:paddingTop=_10dp_
tools:text=_@{}_
android:textColor=_#de000000_
android:textSize=_20sp_
android:lineSpacingMultiplier=__
app:layout_constraintLeft_toLeftOf=_parent_
app:layout_constraintTop_toBottomOf=_@id/apple_regular_ />
程序段P完成RecognitionFragment的布局文件fragment_recognition的定义。