Android页面的布局

本文详细介绍了Android的基础布局,包括LinearLayout的水平和垂直排布,权重分配,以及RelativeLayout的相对定位属性,同时提到了常用的控件如TextView、EditText、ImageView和Button的基本使用。
摘要由CSDN通过智能技术生成

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  (第一种方法,不推荐)

2. 在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

        RelativeLayout 又称相对布局。 从名称上可以看出,这种布局方式是以一种让组件以相对于容器或者相对于容器中的另一个组件的相对位置进行放置的布

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值