Android 应用中的 GridView VS GridLayout

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11307218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:51:19  来源:igfitidea点击:

GridView VS GridLayout in Android Apps

androidgridandroid-gridviewgrid-layout

提问by Lakshmi Sreekanth Chitla

I have to use a Grid to implement Photo Browser in Android. So, I would like to know the difference between GridView and GridLayout.

我必须使用网格在 Android 中实现照片浏览器。所以,我想知道GridView 和 GridLayout 之间区别

So that I shall choose the right one.

这样我才能选择正确的。

Currently I'm using GridView to display the images dynamically.

目前我正在使用 GridView 动态显示图像。

回答by Benito Bertoli

A GridViewis a ViewGroup that displays items in two-dimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view.

GridView的是一个的ViewGroup,在二维网格滚动显示的项目。网格中的项目来自与此视图关联的 ListAdapter。

This is what you'd want to use (keep using). Because a GridView gets its data from a ListAdapter, the only data loaded in memory will be the one displayed on screen. GridViews, much like ListViews reuse and recycle their views for better performance.

这就是您想要使用的(继续使用)。由于 GridView 从 ListAdapter 获取其数据,因此加载到内存中的唯一数据将是屏幕上显示的数据。GridViews,很像 ListViews 重用和回收它们的视图以获得更好的性能。

Whereas a GridLayoutis a layout that places its children in a rectangular grid.

GridLayout是一种将其子项放置在矩形网格中的布局。

It was introduced in API level 14, and was recently backported in the Support Library. Its main purpose is to solve alignment and performance problems in other layouts. Check out this tutorialif you want to learn more about GridLayout.

它是在 API 级别 14 中引入的,最近在支持库中被反向移植。它的主要目的是解决其他布局中的对齐和性能问题。如果您想了解有关 GridLayout 的更多信息,请查看本教程