Androd布局与控件

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 线性布局有两种:

  1. 水平的线性布局 所有控件都是水平挨个排布

    如果没有android:orientation属性的存在

    或者

    android:orientation="horizontal"
  2. 垂直的线性布局 所有控件都是垂直挨个排布

    android:orientation="vertical"

tips: 在android中,所有在页面上显示的东西,必须具备两个属性,这两个属性是宽和高

android:layout_width 宽度

Android:layout_height 高度

对于宽度和高度,他们的值有三个

1. wrap_content  按照内容自适应
1. match_parent  按照父容器尺寸填满
1. 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

第一类属性 属性值为true或者false

android:layout_centerHrizontal 水平居中

android:layout_centerVertical 垂直居中

android:layout_centerInparent 相对于父控件完全居中

android:layout_alignParentBottom 贴紧父控件的下边缘

android:layout_alignParentLeft 贴紧父控件的左边缘

android:layout_alignParentRight 贴紧父控件的右边缘

android:layout_alignParentTop 贴紧父控件的上边缘

android:layout_alignWithParentIfMissing 如果对应的兄弟控件找不到的话,就以父控件作为参照物

 
第二类属性 属性值必须为id的引用名“@id/id-name”

android:layout_below 在某控件下方

android:layout_above 在某控件上方

android:layout_toLeftOf 在某控件的左边

android:layout_toRightOf 在某控件的右边

android:layout_alignTop 本控件的上边缘和某控件的上边缘对齐

android:layout_alignLeft 本控件的左边缘和某控件的左边缘对齐

android:layout_alignBottom 本控件的下边缘和某控件的下控件对齐

android:layout_alignRight 本控件的右边缘和某控件的有边缘对齐

 
第三类:属性值为具体的像素值,如30dip,40px

android:layout_marginBottom 离某控件底边缘的距离

android:layout_marginLeft 离某控件左边缘的距离

android:layout_marginRight 离某控件右边缘的距离

android:layout_marginTop 离某控件上边缘的距离

4. 常用的控件

TextView 文本控件 给用户一个文字性的提示

EditText 输入文本控件

ImageView 图片控件 显示图片

Button 按钮

TextView

  1. 掌握常用的属性

  2. 掌握资源文件的使用

    1. 如何创建资源文件,并对资源文件编程

    2. 使用资源文件

  3. 跑马灯 (自己探索)

  4. 带图片的TextView

    android:drawableTop

重点1:怎么样设置一个shaper(皮肤)

在drawable文件夹下设置 xml

重点2:带图片的TextView

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值