ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

FrameLayout(帧布局,移动端混合开发框架

2021-12-29 16:30:00  阅读:193  来源: 互联网

标签:控件 layout 框架 混合 content FrameLayout wrap android id


在这里插入图片描述

在layout_weight中我们设置它的占据权重为1,则总的权重为1+1+1=3,所以每个控件的所占大小就会是1/3,就会平均分掉这一行的布局。那当我们将其中一个控件的权重修改为2时,就会显示下图的结果。他们的权重比就会是1/4、1/4、2/4。

在这里插入图片描述

RelativeLayout—相对布局


相对布局是通过相对定位的方式制定控件位置,即以其他的控件或父容器为参照物,摆放控件位置。在设计相对布局时要遵循控件之间的依赖关系,后放入的控件的位置要依赖于先放入的控件。

<?xml version="1.0" encoding="utf-8"?>

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

android:layout_width=“match_parent” android:layout_height=“match_parent”

android:paddingBottom=“20dp”>

<Button

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentBottom=“true”

android:text=“按钮1” />

<Button

android:id="@+id/btn_two"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_centerHorizontal=“true”

android:layout_marginTop=“260dp”

android:text=“按钮2”/>

<Button

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignBottom="@+id/btn_two"

android:layout_marginBottom=“100dp”

android:layout_toRightOf="@+id/btn_two"

android:text=“按钮3”/>

在这里插入图片描述

上述代码中,“按钮1”通过 android:layout_alignParentBottom 属性指定当前控件位于布局底端,通过这两个属性的控制,“按钮1”距离底端的距离为20dp。

“按钮2”通过 android:layout_centerHorizontal 属性指定它在父布局中水平居中,通过 android:layout_marginTop 属性指定当前控件上边缘与父布局顶部距离260dp。

“按钮3”通过 android:layout_alignBottom 属性指定它与“按钮2”底部对齐,通过 android:layout_marginBottom属性指定距离“按钮2”底部100dp,android:layout_toRightOf 属性指定了它将被放在按钮2的右边。

相对布局除了上面列出来的一些属性之外,还有其他很多的属性如下所示(参照 http://www.miui.com/thread-574167-1-1.html )

相对于兄弟元素

android:layout_below="@id/aaa":在指定View的下方

android:layout_above="@id/xxx":在指定View的上方

android:layout_toLeftOf="@id/bbb":在指定View的左边

android:layout_toRightOf="@id/cccc":在指定View的右边

相对于父元素

android:layout_alignParentLeft=“true”:在父元素内左边

android:layout_alignParentRight=“true”:在父元素内右边

andro

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

id:layout_alignParentTop=“true”:在父元素内顶部

android:layout_alignParentBottom=“true”:在父元素内底部

对齐方式

android:layout_centerInParent=“true”:居中布局

android:layout_centerVertical=“true”:水平居中布局

android:layout_centerHorizontal=“true”:垂直居中布局

android:layout_alignTop="@id/xxx":与指定View的上边界一致

android:layout_alignBottom="@id/xxx":与指定View下边界一致

android:layout_alignLeft="@id/xxx":与指定View的左边界一致

android:layout_alignRight="@id/xxx":与指定View的右边界一致

间隔

android:layout_marginBottom=""; 离某元素底边缘的距离

android:layout_marginLeft=""; 离某元素左边缘的距离

android:layout_marginRight ="";离某元素右边缘的距离

android:layout_marginTop=""; 离某元素上边缘的距离

android:layout_paddingBottom=""; 离父元素底边缘的距离

android:layout_paddingLeft=""; 离父元素左边缘的距离

android:layout_paddingRight ="";离父元素右边缘的距离

android:layout_paddingTop=""; 离父元素上边缘的距离

FrameLayout—帧布局


帧布局是最为简单的一种布局,该布局为每个加入其中的控件创建一个空白区域,称为一帧,每个控件占据一帧。采用帧布局时,所有控件都默认显示在屏幕左上角,并按照先后放入的顺序重叠摆放,先放入的将会在最底层,后放入的控件显示在最顶层。帧布局使用于图层设计。

其中:foreground 属性设置帧布局容器的前景图像

foregroundGravity 属性设置图像的显示位置

<?xml version="1.0" encoding="utf-8"?>

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

android:layout_width=“match_parent” android:layout_height=“match_parent”

android:foreground="@mipmap/iclauncher"

android:foregroundGravity=“left”>

<Button

android:layout_width=“300dp”

android:layout_height=“450dp”

android:text=“按钮1”/>

<Button

android:layout_width=“200dp”

android:layout_height=“210dp”

android:text=“按钮2”/>

在这里插入图片描述

TableLayout—表格布局


<?xml version="1.0" encoding="utf-8"?>

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

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

<TextView

android:id="@+id/text1"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“①隐藏、收缩、扩展” />

<TableLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:collapseColumns=“2”

android:shrinkColumns=“1”

android:stretchColumns=“0”>

<Button

android:id="@+id/b1"

android:text=“第一列可以行扩展” />

<Button

android:id="@+id/b2"

android:text=“第二列可以列扩展” />

<Button

android:id="@+id/b3"

android:text=“第三列是被隐藏的列” />

<TextView

android:id="@+id/text2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“②单元格的属性设置” />

<TableLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”>

<Button

android:id="@+id/b11"

android:text=“第一列” />

<Button

android:id="@+id/b22"

android:text=“第二列” />

<Button

android:id="@+id/b33"

android:text=“第三列” />

<TextView android:text=“横跨了1到2列………………………”

android:layout_span=“2”

android:layout_column=“1”/>

<TextView

android:id="@+id/text3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

标签:控件,layout,框架,混合,content,FrameLayout,wrap,android,id
来源: https://blog.csdn.net/m0_65512466/article/details/122218819

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有