Android——六大基本布局总结,flutterandroid版本

这篇博客总结了Android中的五大基本布局:LinearLayout、RelativeLayout、FrameLayout、AbsoluteLayout和TableLayout。LinearLayout通过weight属性实现控件的权重分配;RelativeLayout允许子元素相对于彼此或父元素定位;FrameLayout按层次堆叠控件;AbsoluteLayout通过坐标定位,但在多设备适配上受限;TableLayout适合多行多列布局,支持列的伸缩和隐藏。
摘要由CSDN通过智能技术生成

top、bottom、left、right顾名思义为内部控件居顶、低、左、右布局。

这里要与android:layout_gravity区分开,layout_gravity是用来设置自身相对于父元素的布局。

android:layout_weight:权重,用来分配当前控件在剩余空间的大小。

使用权重一般要把分配该权重方向的长度设置为零,比如在水平方向分配权重,就把width设置为零。

先来看一下效果:

下面来看看代码:

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:id="@+id/LinearLayout1"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

tools:context=" r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}" >

<EditText

android:id="@+id/edit"

android:layout_width=“match_parent”

android:layout_height=“wrap_content” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”

android:gravity=“center” >

<Button

android:id="@+id/button"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“确定”/>

<Button

android:id="@+id/button1"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“取消” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal” >

<TextView

android:layout_width=“wrap_content”

android:layout_height=“200dp”

android:layout_weight=“1”

android:background="#ff0000"

android:text=“红色”/>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“200dp”

android:layout_weight=“1”

android:background="#00ff00"

android:text=“绿色”/>

<TextView

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值