Android中的布局

In this tutorial you will learn about different layouts in android.

在本教程中,您将了解android中的不同布局。

Android layouts are used to define the visual structure of user interface. The UI components like label, button, textbox, etc. are defined inside a layout. So before designing UI for an android application you must know about different layouts available in android.

Android布局用于定义用户界面的视觉结构。 UI组件(如标签,按钮,文本框等)在布局内定义。 因此,在为Android应用程序设计UI之前,您必须了解android中可用的不同布局。

There are two ways to design UI in android.

有两种方法可以在android中设计UI。

  • Using XML file

    使用XML档案

  • Using Java code at run time

    在运行时使用Java代码

Designing layout using XML file is better because the presentation of the app is kept separate from the code that controls the behavior. By doing this the debugging and alteration in UI becomes easier. The layout XML files are placed inside res/layout folder.

使用XML文件设计布局会更好,因为应用程序的表示与控制行为的代码是分开的。 这样,UI中的调试和更改变得更加容易。 布局XML文件放置在res / layout文件夹中。

Android中的布局类型 (Types of Layouts in Android)

The various layouts that are available in android are given below. Here I am giving a brief introduction of each layout. I will explain them in detail with example in upcoming tutorials.

以下列出了android中可用的各种布局。 在这里,我简要介绍每种布局。 我将在以后的教程中通过示例详细解释它们。

线性布局 (Linear Layout)

As its name indicates, Linear Layout is used to arrange its children in linear manner, either vertically or horizontally.

顾名思义,线性布局用于以垂直或水平线性方式排列其子级。

Android中的布局

相对布局 (Relative Layout)

This layout is used to place child views relative to each other. We can specify the position of each view or layout relative to sibling or parent.

此布局用于相对于彼此放置子视图。 我们可以指定每个视图或布局相对于同级或父级的位置。

Android中的布局

桌子布局 (Table Layout)

Android中的布局

This layout is used to arrange the child views into rows and columns.

此布局用于将子视图排列为行和列。

绝对布局 (Absolute Layout)

Absolute Layout is used to specify the exact locations of its children in x and y coordinates.

绝对布局用于在x和y坐标中指定其子级的确切位置。

Android中的布局

框架布局 (Frame Layout)

This layout is designed to block out an area on the screen to display a single view.

此布局旨在遮挡屏幕上的某个区域以显示单个视图。

标签布局 (Tab Layout)

It provides a horizontal layout to display tabs.

它提供了用于显示选项卡的水平布局。

列表显示 (List View)

It is used to display a list of vertically scrollable items.

它用于显示垂直可滚动项目的列表。

Android中的布局

网格视图 (Grid View)

It is used to display items in two-dimensional scrolling grid.

它用于在二维滚动网格中显示项目。

Android中的布局

If you found any mistake or have doubts regarding above layouts in android tutorial then feel free to mention it by commenting below.

如果您在Android教程中对上述布局有任何错误或疑问,请随时在下面评论中提及。

翻译自: https://www.thecrazyprogrammer.com/2015/12/layouts-in-android.html