LinearLayout、RelativeLayout 和 AbsoluteLayout 之间有什么区别?

发布于 2024-10-16 03:27:20 字数 85 浏览 5 评论 0原文

我对 LinearLayout、RelativeLayout 和 AbsoluteLayout 之间的区别感到困惑。 有人可以告诉我它们之间的确切区别吗?

I am confused about the difference between LinearLayout, RelativeLayout, and AbsoluteLayout.
Could someone please tell me the exact differences between them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半﹌身腐败 2024-10-23 03:27:20

LinearLayout 意味着您可以将视图一一对齐(垂直/水平)。

RelativeLayout 表示基于其父视图和其他视图之间的关系。

ConstraintLayout 与RelativeLayout 类似,它使用关系来定位和调整小部件的大小,但具有额外的灵活性,并且在布局编辑器中更易于使用。

WebView 加载 html、静态或动态页面。

FrameLayout 将子项加载到另一个之上,就像框架内的卡片一样,我们可以将一个放在另一个之上或框架内的任何位置。

已弃用 - AbsoluteLayout 意味着您必须给出视图应在的确切位置。

有关更多信息,请查看此地址 https://developer.android.com /guide/topics/ui/declaring-layout#CommonLayouts

LinearLayout means you can align views one by one (vertically/ horizontally).

RelativeLayout means based on relation of views from its parents and other views.

ConstraintLayout is similar to a RelativeLayout in that it uses relations to position and size widgets, but has additional flexibility and is easier to use in the Layout Editor.

WebView to load html, static or dynamic pages.

FrameLayout to load child one above another, like cards inside a frame, we can place one above another or anywhere inside the frame.

deprecated - AbsoluteLayout means you have to give exact position where the view should be.

For more information, please check this address https://developer.android.com/guide/topics/ui/declaring-layout#CommonLayouts

唠甜嗑 2024-10-23 03:27:20

定义:

  • 框架布局:其设计目的是在屏幕上遮挡一个区域以显示单个项目。
  • 线性布局:将其子级排列在单列或单行中的布局。
  • 相对布局:此布局是在相对位置显示子视图的视图组。
  • 表布局:将其子项排列为行和列的布局。

更多信息:

FrameLayout

FrameLayout 旨在遮挡屏幕上的一个区域以显示单个项目。一般来说,FrameLayout 应该用于保存单个子视图,因为在子视图不相互重叠的情况下,以可缩放到不同屏幕尺寸的方式组织子视图可能很困难。不过,您可以向 FrameLayout 添加多个子项,并通过使用 android:layout_gravity 属性为每个子项分配重力来控制它们在 FrameLayout 中的位置。

子视图在堆栈中绘制,最近添加的子视图位于顶部。 FrameLayout 的大小是其最大子级的大小(加上填充),无论是否可见(如果 FrameLayout 的父级允许)。

RelativeLayout

RelativeLayout 是一个用于设计用户界面的非常强大的实用程序,因为它可以消除嵌套视图组并保持布局层次结构平坦,从而提高性能。如果您发现自己使用多个嵌套的 LinearLayout 组,则可以将它们替换为单个relativelayout。

(当前文档此处

TableLayout

TableLayout 由许多 TableRow 对象组成,每个对象定义一行(实际上,您可以有其他子对象,这将在下面解释)。 TableLayout 容器不显示其行、列或单元格的边框线。每行有零个或多个单元格;每个单元格可以容纳一个 View 对象。该表的列数与单元格最多的行数相同。表格可以将单元格留空。单元格可以跨列,就像在 HTML 中一样。

列的宽度由该列中单元格最宽的行定义。


注意:绝对布局已被弃用。

Definitions:

  • Frame Layout: This is designed to block out an area on the screen to display a single item.
  • Linear Layout: A layout that arranges its children in a single column or a single row.
  • Relative Layout: This layout is a view group that displays child views in relative positions.
  • Table Layout: A layout that arranges its children into rows and columns.

More Information:

FrameLayout

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.

Child views are drawn in a stack, with the most recently added child on top. The size of the FrameLayout is the size of its largest child (plus padding), visible or not (if the FrameLayout's parent permits).

RelativeLayout

A RelativeLayout is a very powerful utility for designing a user interface because it can eliminate nested view groups and keep your layout hierarchy flat, which improves performance. If you find yourself using several nested LinearLayout groups, you may be able to replace them with a single RelativeLayout.

(Current docs here)

TableLayout

A TableLayout consists of a number of TableRow objects, each defining a row (actually, you can have other children, which will be explained below). TableLayout containers do not display border lines for their rows, columns, or cells. Each row has zero or more cells; each cell can hold one View object. The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML.

The width of a column is defined by the row with the widest cell in that column.


Note: Absolute Layout is deprecated.

月亮是我掰弯的 2024-10-23 03:27:20

LinearLayout: 将其子级组织成单个水平或垂直行的布局。如果窗口的长度超过屏幕的长度,它会创建一个滚动条。这意味着您可以将视图一一对齐(垂直/水平)。

RelativeLayout: 这使您能够指定子对象相对于彼此的位置(子对象 A 位于子对象 B 的左侧)或相对于父对象的位置(与父对象的顶部对齐)。它基于其父母的观点和其他观点的关系。

WebView:加载 html、静态或动态页面。

有关更多信息,请参阅此链接:http://developer.android.com/指南/topics/ui/layout-objects.html

LinearLayout : A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.It means you can align views one by one (vertically/ horizontally).

RelativeLayout : This enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent). It is based on relation of views from its parents and other views.

WebView : to load html, static or dynamic pages.

For more information refer this link:http://developer.android.com/guide/topics/ui/layout-objects.html

远昼 2024-10-23 03:27:20

LinearLayout - 在 LinearLayout 中,视图按垂直或水平方向组织。

RelativeLayout -RelativeLayout 比 LinearLayout 复杂得多,因此提供了更多的功能。顾名思义,视图是相对于彼此放置的。

FrameLayout - 它表现为单个对象,其子视图相互重叠。 FrameLayout 采用最大子元素的大小。

Coordinator Layout - 这是 Android 支持库中引入的最强大的 ViewGroup。它的行为类似于 FrameLayout,并且具有许多在其子视图之间进行协调的功能,例如,浮动按钮和小吃栏、具有可滚动视图的工具栏。

LinearLayout - In LinearLayout, views are organized either in vertical or horizontal orientation.

RelativeLayout - RelativeLayout is way more complex than LinearLayout, hence provides much more functionalities. Views are placed, as the name suggests, relative to each other.

FrameLayout - It behaves as a single object and its child views are overlapped over each other. FrameLayout takes the size of as per the biggest child element.

Coordinator Layout - This is the most powerful ViewGroup introduced in Android support library. It behaves as FrameLayout and has a lot of functionalities to coordinate amongst its child views, for example, floating button and snackbar, Toolbar with scrollable view.

紫竹語嫣☆ 2024-10-23 03:27:20

这里有很好的解释:
https://www.cuelogic.com/博客/使用framelayout-for-designing-xml-layouts-in-android

LinearLayout 水平或垂直并排排列元素。

RelativeLayout 可帮助您根据特定规则排列 UI 元素。您可以指定如下规则:将其与父级的左边缘对齐、将其放置在该元素的左侧/右侧等。

AbsoluteLayout 用于绝对定位,即您可以指定视图应该去的确切坐标。

FrameLayout 允许沿 Z 轴放置视图。这意味着您可以将视图元素一层一层地堆叠起来。

Great explanation here:
https://www.cuelogic.com/blog/using-framelayout-for-designing-xml-layouts-in-android

LinearLayout arranges elements side by side either horizontally or vertically.

RelativeLayout helps you arrange your UI elements based on specific rules. You can specify rules like: align this to parent’s left edge, place this to the left/right of this elements etc.

AbsoluteLayout is for absolute positioning i.e. you can specify exact co-ordinates where the view should go.

FrameLayout allows placements of views along Z-axis. That means that you can stack your view elements one above the other.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文