GridView控件VS网格布局的Andr​​oid应用网格、控件、布局、GridView

2023-09-12 02:36:30 作者:年轻就该狂

我必须使用一个网格来实现图片浏览器在Android中,我想知道GridView和网格布局的差别。

I have to use a grid to implement Photo Browser in Android, and I want to know the difference between GridView and GridLayout.

我使用的GridView动态显示图像(从SD卡)。

I'm using GridView to display the images dynamically (from SD card).

推荐答案

一个 GridView控件是一个的ViewGroup显示在二维滚动网格物品。在网格中的项目来自与该视图关联的ListAdapter。

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

这是你想要什么用(继续使用)。因为一个GridView从ListAdapter获取其数据,加载到内存中的唯一数据将显示在屏幕上的那个。 GridView的,很像列表视图再利用和回收他们的观点有更好的表现。

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.

而一个网格布局是一个布局,将它的孩子在一个长方形的网格。

Whereas a GridLayout is a layout that places its children in a rectangular grid.

据介绍在API级别14,而在支持库最近回迁。 其主要目的是为了解决在其它布局对准和性能问题。 看看这个tutorial如果您想了解更多关于网格布局。

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 tutorial if you want to learn more about GridLayout.