Androd Day02
1. Android的基础布局
LinearLayout 线性布局
RelativeLayout 相对布局
TableLayout 表格布局
FrameLayout 帧布局(框架布局)
ConstrantLayout 约束布局 (Android Studio默认布局) 用于拖拽的
2. LinearLayout 线性布局
2.1 怎么将Android Studio默认的ConstrantLayout改为LinearLayout
1. 在design页面下->component tree->ConstrainLayout右键->Convert view...->选择LinearLayout 点击apply
1. 在code页面下->直接修改代码 将 androidx.constraintlayout.widget.ConstraintLayout 改为 LinearLayout
2.2 线性布局有两种:
-
水平的线性布局 所有控件都是水平挨个排布
如果没有android:orientation属性的存在
或者
android:orientation="horizontal"
-
垂直的线性布局 所有控件都是垂直挨个排布
android:orientation="vertical"
tips: 在android中,所有在页面上显示的东西,必须具备两个属性,这两个属性是宽和高
android:layout_width 宽度
Android:layout_height 高度
对于宽度和高度,他们的值有三个
- wrap_content 按照内容自适应
- match_parent 按照父容器尺寸填满
- 50dp 数值(用的地方很单一)
2.3 比重:
android:layout_weight
如何算总比重: 看同一父亲且同一级的各个控件的weight
一旦weight属性生效,android:layout_width失效
2.4 布局排布:
android:gravity 内容位置改变
android:layout_gravity 本身位置改变
2.5 分隔线:内部的线
android:divider="@color/black"
android:showDividers="middle"
2.6 嵌套线性布局结构
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
属性详细在下面评论区
3. RelativeLayout
4. 常用的控件
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mT8h7JPM-1657864754605)(C:\Users\Administrator\Desktop\资料\图片\20220715134215.png)]
TextView 文本控件 给用户一个文字性的提示
EditText 输入文本控件
ImageView 图片控件 显示图片
Button 按钮
设置控件边框
设置一个矩形
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> //代表设置一个矩形
<solid android:color="#FFFFFF"> //代表设置矩形的背景色
<stroke android:width="8dp" //代表设置边框的厚度
android:color="@color/black"/> //代表设置边框的颜色
</shape>
圆形边框设置
android:shape=“ovasl” 代表设置一个椭圆形
solid android:color="#FFFFFF" 代表设置椭圆形的背景色
stroke android:width=“3dp” 代表设置边框的厚度
android:color="@color/black" 代表设置边框的颜色
设置下划线
android:shape=“line” 代表设置一个线形
solid android:color="#FFFFFF" 代表设置线形的背景色
stroke android:width=“6dp” 代表设置线段的厚度
android:color="@color/black" 代表设置线段的颜色
详细的属性说明
(1条消息) Android Studio控件属性大全_weixin_46058506的博客-优快云博客_android studio属性
详细的控件说明
[(1条消息) android 梯形按钮_android shape绘制常用的形状_weixin_39589644的博客-优快云博客](https://blog.youkuaiyun.com/weixin_39589644/article/details/111521933?ops_request_misc=&request_id=&biz_id=102&utm_term=Android Studio设置半角矩形&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-111521933.142v32pc_rank_34,185v2control&spm=1018.2226.3001.4187)
dio设置半角矩形&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-111521933.142v32pc_rank_34,185v2control&spm=1018.2226.3001.4187)