Android Studio 学习记录:第三天

一、回顾与总结在前两天的学习中,我掌握了 Android Studio 的基本操作,包括项目结构、布局设计基础(线性布局和相对布局)以及基本组件的使用。我还学会了如何运行和调试应用。这些知识为我今天的进阶学习奠定了坚实的基础。二、学习目标1. 深入学习 ConstraintLayout:掌握 ConstraintLayout 的布局方式和约束规则。2. 学习更多 UI 组件:如 EditText、ImageView 等,并实现更复杂的交互功能。3. 理解事件处理机制:掌握点击事件、长按事件等的处理方法。4. 学习数据存储基础:了解 SharedPreferences 的使用方法。三、ConstraintLayout 布局ConstraintLayout 是一种强大的布局方式,允许开发者通过约束(Constraints)来定义组件的位置和大小。它能够替代传统的嵌套布局,减少布局层级,提高性能。(一)ConstraintLayout 的基本属性• app:layout_constraintTop_toTopOf :组件顶部与目标组件顶部对齐。• app:layout_constraintBottom_toBottomOf :组件底部与目标组件底部对齐。• app:layout_constraintLeft_toLeftOf :组件左侧与目标组件左侧对齐。• app:layout_constraintRight_toRightOf :组件右侧与目标组件右侧对齐。• app:layout_constraintStart_toStartOf :组件起始端与目标组件起始端对齐(支持 RTL 布局)。• app:layout_constraintEnd_toEndOf :组件结束端与目标组件结束端对齐(支持 RTL 布局)。(二)示例代码xml<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">

posted @ 2025-03-15 21:42  马瑞鑫03  阅读(41)  评论(0)    收藏  举报