Xamarin Android 布局Xamarin.Android Layouts

布局用于排列组成屏幕 UI 界面(如活动)的元素。Layouts are used to arrange the elements that make up the UI interface of a screen (such as an Activity). 以下部分介绍如何在 Xamarin Android 应用中使用最常用的布局。The following sections explain how to use the most commonly-used layouts in Xamarin.Android apps.

  • LinearLayout是一个视图组,它以垂直或水平方式以线性方向显示子视图元素。LinearLayout is a view group that displays child view elements in a linear direction, either vertically or horizontally.

    线性布局示例

  • RelativeLayout是在相对位置显示子视图元素的视图组。RelativeLayout is view group that displays child view elements in a relative position. 可以将视图的位置指定为相对于同级元素。The position of a view can be specified as relative to sibling elements.

    示例相对布局

  • TableLayout是一个视图组,用于显示行和列中的子视图元素。TableLayout is a view group that displays child view elements in rows and columns.

    示例表布局

  • RecyclerView是一个 UI 元素,用于显示列表或网格中的项集合,使用户能够滚动浏览该集合。RecyclerView is a UI element that displays a collection of items in a list or a grid, enabling the user to scroll through the collection.

    示例 Recycler 视图

  • ListView是创建可滚动项列表的视图组。ListView is a view group that creates a list of scrollable items. 列表项自动使用列表适配器插入列表中。The list items are automatically inserted into the list using a list adapter. ListView 是 Android 应用程序的重要 UI 组件,因为它可用于从菜单选项的简短列表到长列表的联系人或 internet 收藏夹。The ListView is an important UI component of Android applications because it is used everywhere from short lists of menu options to long lists of contacts or internet favorites. 它提供了一种简单的方法来显示可使用内置样式或广泛自定义的行的滚动列表。It provides a simple way to present a scrolling list of rows that can either be formatted with a built-in style or customized extensively. ListView 实例需要适配器,以便将其与行视图中包含的数据一起馈送。A ListView instance requires an Adapter to feed it with data contained in row views.

    示例列表视图

  • GridView是一个 UI 元素,用于显示二维网格中可滚动的项。GridView is a UI element that displays items in a two-dimensional grid that can be scrolled.

    网格视图示例

  • GridLayout是一个视图组,支持在二维网格中布局视图,这与 HTML 表类似。GridLayout is a view group that supports laying out views in a 2D grid, similar to an HTML table.

    网格布局示例

  • 在移动应用程序中,选项卡式布局是一种常用的用户界面模式,因为它们简单易用。Tabbed Layouts are a popular user interface pattern in mobile applications because of their simplicity and usability. 它们提供了一种在应用程序的不同屏幕之间导航的一致且简单的方法。They provide a consistent, easy way to navigate between various screens in an application.

    选项卡式布局示例