Android Studio菜鸟开发————LinearLayout线性布局

本文介绍了Android Studio中LinearLayout布局的使用,重点讲解了`android:layout_height="match_parent"`属性以及`android:layout_weight`属性如何按比例分配控件的剩余空间。通过示例展示了不同权重比对控件布局的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在content_main.xml中可以这样写:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.a1.myfirstp.MainActivity"
    tools:showIn="@layout/activity_main"
    android:orientation="vertical"
    >

</LinearLayout>
android:layout_width="match_parent"   表示宽的属性为match_parent(匹配父控件),还可以设置为wrap_content(包含内容)

android:layout_height="match_parent" 高的属性

android:orientation="vertical"    orientation表示排列方式,vertical表示垂直排列,也可以用horizontal水平排列
可以嵌套线性布局:
<LinearLayout>
<LinearLayout></LinearLayout>

</LinearLayout>

线性布局中的控件可以使用android:layout_weight属性,表示将父控件的剩余空间按比例分配;

如第一个控件的weight值为1,第二个为1;表示将父控件的剩余空间按1:1分配(不包括控件text内容的大小)

第一个值为2,第二个值为1,表示按2:1分配,以此类推;


 


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值