| |
|
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
| -> 移动开发 -> Android界面布局 -> 正文阅读 |
|
|
[移动开发]Android界面布局 |
|
Android布局实验——线性布局
?
利用线性布局实现如下界面:
?实验过程: 刚刚接触Android studio,面对第一个实验有些无从下手,所以先收集了资料。 线性布局的重点为:vertical(垂直布局);horizontal(水平布局) 线性布局由:LinearLayout类来代表,它可以控制各组件横向排列,也可以控制各组件纵向排列。 所以四行四列,运用嵌套,先用一个垂直的LinearLayout,里面放四个水平的LinearLayout,然后在水平的LinearLayout里面放TextView。 部分代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView... />
<TextView... />
<TextView.../>
<TextView... />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView.../>
<TextView... />
<TextView.../>
<TextView.../>
</LinearLayout>...
为了达到如图上的间隔效果,加入 <TextView android:layout_marginTop="5px" android:layout_marginBottom="5px" android:layout_marginLeft="5px" android:layout_marginRight="5px"/> 为了达到如图上的边框效果,在shape.xml中加入 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1px" android:color="#fff"/>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
</shape>
最后得到:
Android布局实验——约束布局
?? 利用ConstraintLayout实现如下界面:
约束布局中最重要的为被约束的组件的位置,以及 相对定位的常用属性: (作者:四会歌神陈子豪 只要弄清楚组件与组件之间的位置,就可以很好的运用ConstraintLayout 先固定input组件: <TextView ... android:id="@+id/TextView1" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> 然后利用input组件固定好结果组件: <TextView
android:id="@+id/TextView2"
app:layout_constraintEnd_toEndOf="@id/TextView1"
app:layout_constraintTop_toBottomOf="@id/TextView1"
app:layout_constraintStart_toStartOf="@id/TextView1"
/>
只要固定好以上两个界面,下面的计算器案件部分,就很简单了 <Button
android:id="@+id/Button1"
...
app:layout_constraintTop_toBottomOf="@id/TextView2"
app:layout_constraintLeft_toLeftOf="@id/TextView2"
tools:ignore="MissingConstraints">
</Button>
<Button
android:id="@+id/Button2"
...
app:layout_constraintTop_toBottomOf="@id/TextView2"
app:layout_constraintLeft_toRightOf="@id/Button1"
app:layout_constraintBaseline_toBaselineOf="@id/Button1"
tools:ignore="MissingConstraints">
</Button>
<Button
android:id="@+id/Button3"
...
app:layout_constraintTop_toBottomOf="@id/TextView2"
app:layout_constraintLeft_toRightOf="@id/Button2"
app:layout_constraintBaseline_toBaselineOf="@id/Button2"
tools:ignore="MissingConstraints">
</Button>
<Button
android:id="@+id/Button4"
...
app:layout_constraintTop_toBottomOf="@id/TextView2"
app:layout_constraintLeft_toRightOf="@id/Button3"
app:layout_constraintBaseline_toBaselineOf="@id/Button3"
tools:ignore="MissingConstraints">
</Button>
按键第一层出现,后面的以此对应上面的约束即可 PS:虽然使用的组件与计算器的无关,但是我已经尽量图片上模仿了。
Android布局实验——表格布局
?
利用表格布局实现如下界面:
?表格布局由TableLayout所代表,它与LinearLayout类似,但不需要明确包含多少行,多少列,而是通过添加TableRow和其他组件来控制表格的行数和列数。 TableRow代表一行,一行中有几列则由TableRow中有多少组件决定。 PS:因为我不太看得懂老师这个到底是哪里运用了表格,所以就按照我自己的理解,每一行由2到3列,中间的留白部分,我用拉伸但不输入文字的 <TextView
android:text="">
</TextView>
如果有错误还请大家多多指教,不要骂我谢谢谢谢( ?? ω ?? )? 我的结果如下:
?新手还请大家多多指教,三个实验其实都不太会╥﹏╥... |
|
|
| 移动开发 最新文章 |
| Vue3装载axios和element-ui |
| android adb cmd |
| 【xcode】Xcode常用快捷键与技巧 |
| Android开发中的线程池使用 |
| Java 和 Android 的 Base64 |
| Android 测试文字编码格式 |
| 微信小程序支付 |
| 安卓权限记录 |
| 知乎之自动养号 |
| 【Android Jetpack】DataStore |
|
|
| 上一篇文章 下一篇文章 查看所有文章 |
|
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
| 360图书馆 购物 三丰科技 阅读网 日历 万年历 2025年11日历 | -2025/11/28 21:10:26- |
|
| 网站联系: qq:121756557 email:121756557@qq.com IT数码 |