【Android】基础篇:Android Studio中布局管理器

大家好,我是皮皮猫。
每文一言: 不要活在别人眼中,更不要活在别人嘴中。世界不会因为你的抱怨不满而为你改变,你能做到的只有改变你自己!


本篇文章:

主要是关于Android Studio中布局管理器的内容。

进入正文:
一、线性布局(LinearLayOut)

1)找到代码文件:activity_main.xml
在这里插入图片描述
修改为线性布局:
在这里插入图片描述
线性布局属性:
在这里插入图片描述
id: 标识,通过id找到控件
layout_width: 控件的宽度
layout_height: 控件的高度
background: 控件的背景
layout_margin: 控件外边距
layout_padding: 控件内部边距
orientation: 方向
2)文本控件:
代码:
在这里插入图片描述
分析:

    wrap_contenet:表示让当前的控件大小能够刚好包含里面的内容,由控件的内容决定当前控件的大小
    match_parent:表示让当前控件的大小和父布局的大小一样,也就是由父布局来决定当前控件的大小
    android:text:表示的是控件是一个文本

效果展示:
在这里插入图片描述
3)线性控件
代码:
在这里插入图片描述
分析:

<LinearLayout                                       线性代码块关键字
    android:id="@+id/ll_1"                       控件id属性
    android:layout_width="200dp"            控件宽度属性  
    android:layout_height="200dp"           控件高度属性
    android:orientation="vertical"              控件方向:Vertical:垂直排列,horizontal:横向排列
    android:background="#000f0f"            控件背景属性
    android:padding="20dp"                    控件内部边距
    android:layout_marginTop="20dp"        控件外边距顶部 
    android:layout_marginBottom="20dp">  控件外边距底部  
    <View                                               View是所有控件的父类,所有的控件都继承View
        android:layout_width="match_parent"  match_parent:跟父控件的宽度一样
        android:layout_height="match_parent"    match_parent:跟父控件的高度一样(此时的父控件是:LinearLayout )                          
        android:background="#ff0033"/>         设置背景颜色
</LinearLayout>

效果展示:
在这里插入图片描述
4)线性控件
代码:
在这里插入图片描述
分析:

<LinearLayout    
    android:layout_width="match_parent"    
    android:layout_height="200dp"    
    android:orientation="horizontal"    
    android:background="#0066ff"    
    android:layout_marginLeft="15dp"    
    android:layout_marginRight="15dp"    
    android:padding="10dp">    
    <!--android:gravity="center" -->   设置子类控件位置居中
 
    <View        
        android:layout_width="50dp"        
        android:layout_height="match_parent"        
        android:background="#000000"        
        android:layout_weight="1"        />    
        <!--layout_weight:父控件剩余空间按照比重分配 -->    

    <View        
        android:layout_width="50dp"        
        android:layout_height="match_parent"        
        android:background="#ff0033"        
        android:layout_weight="1"        />    

    <View        
        android:layout_width="50dp"        
        android:layout_height="match_parent"        
        android:background="#D52BD5"        
        android:layout_weight="1"        />
</LinearLayout>

效果展示:
在这里插入图片描述

二、相对布局

1)相对布局属性:
在这里插入图片描述
具有线性布局的那些属性,也具有如下属性:
layout_toLeftOF: 在谁的左边
layout_toRoghtOF: 在谁的右边
layout_alignBottom: 跟谁的底部对齐
layout_alignParentBottom: 跟父控件底部对齐
layout_below: 在谁的下边

2)例子1:
代码:
在这里插入图片描述
分析:

<View    
android:id="@+id/view_1"    
android:layout_width="100dp"    
android:layout_height="100dp"    
android:background="#000000" />

<!--    
android:layout_alignParentBottom="true"    
android:layout_alignParentRight="true"    
layout_alignParentBottom:在父控件的底部    
layout_alignParentRight:在父控件的右边    
综合:在父控件的右下角-->

效果展示:
在这里插入图片描述

3)例子2:
代码:
在这里插入图片描述
分析:

    <View        
    android:id="@+id/view_2"        
    android:layout_width="100dp"        
    android:layout_height="100dp"        
    android:background="#EE113D"        
    android:layout_below="@+id/view_1"/>    
    <!--layout_below:在id为view_1的下边-->

效果展示:
在这里插入图片描述
4)例子3:
代码:
在这里插入图片描述
分析:

<LinearLayout    
    android:id="@+id/ll_1"    
    android:layout_width="match_parent"    
    android:layout_height="200dp"    
    android:layout_below="@id/view_2"    位置在id为view_2控件的下面
    android:background="#3333CC"    
    android:orientation="horizontal"    设置方向为水平
    android:padding="10dp">        

    <View        
        android:layout_width="100dp"        
        android:layout_height="match_parent"        
        android:background="#EE113D"        />    

    <RelativeLayout        
        android:layout_width="match_parent"        
        android:layout_height="match_parent"        
        android:background="#000000"        
        android:layout_marginLeft="20dp"        
        android:padding="15dp">        

        <View            
            android:id="@+id/view_3"            
            android:layout_width="100dp"            
            android:layout_height="match_parent"            
            android:background="#BD1AE6"/>        

        <View            
            android:id="@+id/view_4"            
            android:layout_width="100dp"            
            android:layout_height="match_parent"            
            android:background="#5EA2A2"            
            android:layout_toRightOf="@id/view_3"     位置在id为View_3控件的右边       
            android:layout_marginLeft="20dp"/>          右外边距为20dp

    </RelativeLayout>
</LinearLayout>

注意:
View控件只有在RelativeLayout下面才可以有相对位置

效果展示:
在这里插入图片描述


完结,撒花…

更多Android Studio学习,持续更新中…

作者:皮皮猫


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值