- Material UI 简介
 - Material UI 组件库详解
 - 使用 Material UI 的 Autocomplete 组件详解
 - 使用 Material UI 的 Button 组件详解
 - 使用 Material UI 创建按钮组(Button Group)的详细指南
 - 使用 Material UI 创建复选框(Checkbox)的详细指南
 - Material UI 中 Floating Action Button 的使用详解
 - Material UI 中 Radio Group 的使用详解
 - Material UI 中 Rating 组件的使用详解
 - Material UI 中 Select 组件的使用详解
 - Material UI 中 Slider 组件的使用详解
 - Material UI Switch 组件使用详解
 - Material UI Text Field 组件使用详解
 - Material UI Transfer List 使用详解
 - Material UI Toggle Button 使用详解
 - Material UI Avatar 组件使用详解
 - Material UI Badge 组件使用详解
 - Material UI Chip 组件使用详解
 - Material UI Divider 组件使用详解
 - Material UI Icons 组件使用详解
 - Material UI 中 Material Icons 的使用详解
 - Material UI 框架中 Lists 的使用详解
 - Material UI 框架中 Table 的使用详解
 - Material UI 框架中 Tooltip 的使用详解
 - Material UI 框架中 Typography 的使用详解
 - Material UI 框架中 Alert 组件的使用详解
 - Material UI 框架中 Backdrop 组件的详细使用教程
 - Material UI 框架中 Dialog 组件的详细使用教程
 - Material UI Progress 组件详解及示例
 - Material UI 框架中的 Skeleton 组件详解
 - Material UI 框架中的 Snackbar 组件详解
 - Material UI 框架中的 Accordion 组件详解
 - Material UI 框架中的 App Bar 组件详解
 - Material UI 框架中的 Card 组件详解
 - Material UI 框架中的 Paper 组件详解
 - 使用 Material UI 框架中的 Bottom Navigation 组件
 - 使用 Material UI 框架中的 Breadcrumbs 组件
 - 使用 Material UI 框架中的 Drawer 组件
 - 使用 Material UI 框架中的 Links 组件
 - 使用 Material UI 框架中的 Menu 组件
 - 使用 Material UI 框架中的 Pagination 组件
 - 使用 Material UI 框架中的 Speed Dial 组件
 - 使用 Material UI 框架中的 Stepper 组件
 - 使用 Material UI 框架中的 Tabs 组件
 - 使用 Material UI 框架中的 Layout Box 组件
 - 使用 Material UI 框架中的 Layout Container
 - 使用 Material UI 框架中的 Layout Grid
 - 使用 Material UI 框架中的 Layout Grid Version 2
 - 使用 Material UI 框架中的 Layout Stack
 - 使用 Material UI 框架中的 Layout Image List
 - 使用 Material UI 框架中的 Layout Hidden
 - 使用 Material UI 框架中的 Click-Away Listener
 - 使用 Material UI 框架中的 CSS Baseline
 - 使用 Material UI 框架中的 Utils Modal
 - 使用 Material UI 框架中的 Utils No SSR
 - 使用 Material UI 框架中的 Utils Popover
 - 使用 Material UI 框架中的 Utils Popper
 - 使用 Material UI 框架中的 Utils Portal
 - 使用 Material UI 框架中的 Utils Textarea Autosize
 - 使用 Material UI 框架中的 Utils Transitions
 - 使用 Material UI 框架中的 `useMediaQuery`
 - 使用 Material UI 框架中的 MUI X Data Grid
 - 使用 Material UI 框架中的 Data Grid - Layout
 - 使用 Material UI 框架中的 Data Grid:深入探索列定义与管理
 - 深入探索 Material UI 框架中的 Data Grid:行定义与管理
 - 深入探索 Material UI 框架中的 Data Grid 编辑功能
 - 深入探索 Material UI 框架中的 Data Grid 排序功能
 - 深入探索 Material UI 框架中的 Data Grid 过滤功能
 - 深入探索 Material UI 框架中的 Data Grid 分页功能
 - 深入探索 Material UI 框架中的 Data Grid 行选择和单元格选择功能
 - 深入探索 Material UI 框架中的 Data Grid 导出功能
 - 深入探索 Material UI 框架中的 Data Grid - Copy and Paste 功能
 - 深入探索 Material UI 框架中的 Data Grid - Overlays 功能
 - 深入探索 Material UI 框架中的 Data Grid - Custom Slots and Subcomponents
 - 深入探索 Material UI 框架中的 Data Grid - Styling 和 Styling Recipes
 - 深入探索 Material UI 框架中的 Data Grid - Translated Components
 - 使用 Material UI 的 Data Grid - Scrolling 功能
 - 使用 Material UI 的 Data Grid - Virtualization 功能
 - 使用 Material UI 的 Data Grid - 可访问性(Accessibility)功能
 - 使用 Material UI 的 Data Grid - 性能(Performance)优化
 - 使用 Material UI 的 Data Grid - 树形数据(Tree Data)
 - 使用 Material UI 的 Data Grid - 行分组(Row Grouping)
 - 使用 Material UI 的 Data Grid - 数据聚合(Aggregation)
 - 使用 Material UI 的 Data Grid - 数据透视(Pivoting)
 - 使用 Material UI 的 Data Grid - 服务器端数据(Server-side Data)
 - 使用 Material UI 的 Data Grid - 服务器端树形数据(Server-side Tree Data)
 - 使用 Material UI 的 Data Grid - 服务器端懒加载(Server-side Lazy Loading)
 - 使用 Material UI 的 Data Grid - 服务器端行分组(Server-side Row Grouping)
 - 使用 Material UI 的 Data Grid - 服务器端聚合(Server-side Aggregation)
 - 使用 Material UI 的 Data Grid - API Object
 - 使用 Material UI 的 Data Grid - 事件处理(Events)
 - 使用 Material UI 的 Data Grid - State 管理
 - Material UI Data Grid - 编辑功能详解与使用示例
 - Material UI Data Grid - Row Grouping 使用指南与示例
 - Material UI DataGrid API 使用指南
 - Material UI DataGridPremium API 使用指南
 - Material UI 框架 DataGridPro API 使用指南
 - Material UI 框架 GridFilterForm API 使用指南
 - Material UI 框架 GridFilterPanel API 使用指南
 - Material UI 框架 GridApi API 使用指南
 - Material UI 框架 GridCellParams API 使用指南
 - Material UI 框架 GridColDef API 使用指南
 - Material UI 框架 GridSingleSelectColDef API 使用指南
 - Material UI 框架 GridActionsColDef API 使用指南
 - Material UI 框架 GridExportStateParams API 使用指南
 - Material UI 框架 GridFilterItem API 使用指南
 - Material UI 框架 GridFilterModel API 使用指南
 - Material UI 框架:GridToolbarQuickFilter API 使用详解
 - Material UI 框架:GridApi 接口详解及其使用
 - Material UI 框架:Interface `GridCellParams` API 使用详解
 - Material UI 框架:Interface `GridColDef` API 使用详解
 - Material UI 框架:Interface `GridSingleSelectColDef` API 使用详解
 - Material UI 框架:Interface `GridActionsColDef` API 使用详解
 - Material UI 框架:Interface `GridExportStateParams` API 使用详解
 - Material UI 框架:`GridFilterItem` API 使用详解
 - Material UI 框架:`GridFilterModel` API 使用详解
 - Material UI 框架:`Interface GridFilterOperator` API 使用详解
 - Material UI 框架:`GridRowClassNameParams` 接口详解及使用指南
 - Material UI 框架:`GridRowParams` 接口详解及使用指南
 - Material UI 框架:`GridRowSpacingParams` 接口详解及使用指南
 - Material UI 框架:`GridAggregationFunction` 接口详解及使用指南
 - Material UI 框架:`GridCsvExportOptions` 接口详解及使用指南
 - Material UI 框架:`GridPrintExportOptions` 接口详解及使用指南
 - Material UI 框架:`GridExcelExportOptions` 接口详解及使用指南
 - Material UI 框架:MUI X 日期和时间选择器使用指南
 - Material UI 框架:日期和时间选择器 - 入门指南
 - Material UI 框架:日期和时间选择器 - 基本概念
 - Material UI 框架:日期和时间选择器 - 可访问性
 - Material UI 框架之 Date Picker 组件详解
 - Material UI 框架之 Date Field 组件详解
 - Material UI 框架之 Date Calendar 组件详解
 - Material UI 框架之 Time Picker 组件详解
 - Material UI 框架之 Time Field 组件详解
 - Material UI 框架之 Time Clock 组件详解
 - Material UI 框架之 Digital Clock 组件详解
 - Material UI 框架之 DateTime Picker 组件详解
 - Material UI 框架之 DateTime Field 组件详解
 - Material UI 组件 Date Range Picker 使用详解
 - Material UI 组件 Date Range Field 使用详解
 - Material UI 组件 Date Range Calendar 使用详解
 - Material UI 组件 Time Range Picker 使用详解
 - Material UI 组件 Time Range Field 使用详解
 - Material UI 组件 Date Time Range Picker 使用详解
 - Material UI 组件 Date Time Range Field 使用详解
 - 使用 Material-UI 的 Fields 组件详解
 - 使用 Material-UI 的 DateCalendar 组件详解
 - 使用 Material-UI 的 DateField 组件详解
 - 使用 Material-UI 的 DatePicker 组件详解
 - 使用 Material-UI 的 DatePickerToolbar API 详解
 - 使用 Material-UI 的 DateRangeCalendar API 详解
 - 使用 Material-UI 的 DateRangePicker API 详解
 - 使用 Material-UI 的 DateRangePickerDay API 详解
 - 使用 Material UI DateRangePickerToolbar API 详解
 - 深入了解 Material UI DateTimeField API 使用
 - 深入了解 Material UI DateTimePicker API 使用
 - 深入了解 Material UI `DateTimePickerTabs` API 的使用
 - 深入了解 Material UI 框架中的 `DateTimePickerToolbar` API
 - 深入了解 Material UI 框架中的 `DateTimeRangePicker` API
 - Material UI 框架中的 DateTimeRangePickerTabs API 使用详解
 - 深入了解 Material UI 框架中的 `DateTimeRangePickerToolbar API`
 - 深入了解 Material UI 框架中的 `DayCalendarSkeleton API`
 - 深入解析 Material UI 的 DesktopDatePicker API 使用指南
 - 深入解析 Material UI 的 `DesktopDateRangePicker API` 使用指南
 - 深入解析 Material UI 的 `DesktopDateTimePicker API` 使用指南
 - 深入解析 Material UI 的 `DesktopDateTimeRangePicker API` 使用指南
 - 深入解析 Material UI 的 `DesktopTimePicker API` 使用指南
 - 深入解析 Material UI 的 `DigitalClock API` 使用指南
 - 深入解析 Material UI 的 `LocalizationProvider API` 使用指南
 - Material UI 框架中 MobileDatePicker API 的全面使用指南
 - 深入了解 Material UI 的 MobileDateRangePicker API 使用
 
使用 Material UI 框架中的 Layout Image List
class Image ListMaterial UI 的 Layout Image List 组件是一个强大的工具,用于以响应式的方式展示图像。它特别适用于需要展示图像网格的应用场景,比如相册、产品展示等。本篇博客将详细介绍 Layout Image List 的使用,包括基本用法、属性、方法及与其他组件结合的示例。
1. 安装 Material UI
首先,确保你已经在项目中安装了 Material UI:
npm install @mui/material @emotion/react @emotion/styled
2. Image List 组件概述
ImageList 组件用于展示一组图像,支持响应式布局和不同的排列方式。你可以通过设置不同的属性来控制图像的显示效果。
2.1 基本用法
以下是一个基本的 ImageList 组件示例:
import React from 'react';
import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem';
function BasicImageList() {
  const itemData = [
    {
      img: 'https://via.placeholder.com/200',
      title: 'Image 1',
    },
    {
      img: 'https://via.placeholder.com/200',
      title: 'Image 2',
    },
    {
      img: 'https://via.placeholder.com/200',
      title: 'Image 3',
    },
  ];
  return (
    <ImageList sx={{ width: 500, height: 450 }} cols={3} rowHeight={164}>
      {itemData.map((item) => (
        <ImageListItem key={item.img}>
          <img
            src={`${item.img}?w=164&h=164&fit=crop&auto=format`}
            srcSet={`${item.img}?w=164&h=164&fit=crop&auto=format&dpr=2 2x`}
            alt={item.title}
            loading="lazy"
          />
        </ImageListItem>
      ))}
    </ImageList>
  );
}
export default BasicImageList;
3. Image List 组件的属性
ImageList 和 ImageListItem 组件提供了一些非常实用的属性,以下是主要属性的详细介绍:
3.1 ImageList 属性
- 
cols:
number- 默认值: 
2 - 描述: 设置每行显示的列数。
 
 - 默认值: 
 - 
rowHeight:
number | 'auto'- 默认值: 
164 - 描述: 设置每行的高度,可以使用固定数值或 
'auto'。 
 - 默认值: 
 - 
gap:
number- 默认值: 
0 - 描述: 设置图像之间的间距。
 
 - 默认值: 
 - 
variant:
string- 描述: 设置列表的变体。可选值有:
'masonry': 瓦片布局'quilted': 拼图布局'standard': 标准布局'woven': 交织布局
 
 - 描述: 设置列表的变体。可选值有:
 
3.2 ImageListItem 属性
- 
key:
string- 描述: 每个子项的唯一标识符。
 
 - 
img:
string- 描述: 图像的 URL。
 
 - 
title:
string- 描述: 图像的标题。
 
 
4. Image List 组件的示例
4.1 使用不同的布局
4.1.1 瓦片布局
import React from 'react';
import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem';
function MasonryImageList() {
  const itemData = [
    {
      img: 'https://via.placeholder.com/300x200',
      title: 'Masonry Image 1',
    },
    {
      img: 'https://via.placeholder.com/200x300',
      title: 'Masonry Image 2',
    },
    {
      img: 'https://via.placeholder.com/250x250',
      title: 'Masonry Image 3',
    },
  ];
  return (
    <ImageList variant="masonry" cols={3} gap={8}>
      {itemData.map((item) => (
        <ImageListItem key={item.img}>
          <img
            src={`${item.img}?w=164&h=164&fit=crop&auto=format`}
            alt={item.title}
            loading="lazy"
          />
        </ImageListItem>
      ))}
    </ImageList>
  );
}
export default MasonryImageList;
4.2 使用标题和图像描述
import React from 'react';
import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem';
import ImageListItemBar from '@mui/material/ImageListItemBar';
import Typography from '@mui/material/Typography';
function ImageListWithTitle() {
  const itemData = [
    {
      img: 'https://via.placeholder.com/200',
      title: 'Image 1',
      description: 'This is the first image.',
    },
    {
      img: 'https://via.placeholder.com/200',
      title: 'Image 2',
      description: 'This is the second image.',
    },
  ];
  return (
    <ImageList sx={{ width: 500, height: 450 }} cols={2} rowHeight={164}>
      {itemData.map((item) => (
        <ImageListItem key={item.img}>
          <img
            src={`${item.img}?w=164&h=164&fit=crop&auto=format`}
            alt={item.title}
            loading="lazy"
          />
          <ImageListItemBar
            title={item.title}
            subtitle={<Typography variant="body2">{item.description}</Typography>}
          />
        </ImageListItem>
      ))}
    </ImageList>
  );
}
export default ImageListWithTitle;
4.3 响应式布局
import React from 'react';
import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem';
import useMediaQuery from '@mui/material/useMediaQuery';
function ResponsiveImageList() {
  const itemData = [
    {
      img: 'https://via.placeholder.com/200',
      title: 'Responsive Image 1',
    },
    {
      img: 'https://via.placeholder.com/200',
      title: 'Responsive Image 2',
    },
    {
      img: 'https://via.placeholder.com/200',
      title: 'Responsive Image 3',
    },
  ];
  const isSmallScreen = useMediaQuery('(max-width:600px)');
  const cols = isSmallScreen ? 1 : 3;
  return (
    <ImageList sx={{ width: '100%', height: 'auto' }} cols={cols}>
      {itemData.map((item) => (
        <ImageListItem key={item.img}>
          <img
            src={`${item.img}?w=164&h=164&fit=crop&auto=format`}
            alt={item.title}
            loading="lazy"
          />
        </ImageListItem>
      ))}
    </ImageList>
  );
}
export default ResponsiveImageList;
5. Image List 与其他组件结合使用
5.1 Image List 与 Card 结合
将 ImageList 与 Card 组件结合使用,创建图像卡片布局:
import React from 'react';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem';
import Typography from '@mui/material/Typography';
function CardImageListExample() {
  const itemData = [
    {
      img: 'https://via.placeholder.com/300',
      title: 'Card Image 1',
    },
    {
      img: 'https://via.placeholder.com/300',
      title: 'Card Image 2',
    },
  ];
  return (
    <Card>
      <CardContent>
        <Typography variant="h5">图像卡片示例</Typography>
        <ImageList cols={2}>
          {itemData.map((item) => (
            <ImageListItem key={item.img}>
              <img
                src={`${item.img}?w=164&h=164&fit=crop&auto=format`}
                alt={item.title}
                loading="lazy"
              />
            </ImageListItem>
          ))}
        </ImageList>
      </CardContent>
    </Card>
  );
}
export default CardImageListExample;
5.2 Image List 与 Dialog 结合
使用 ImageList 在 Dialog 中展示大图:
import React, { useState } from 'react';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem';
function DialogImageListExample() {
  const [open, setOpen] = useState(false);
  const handleClickOpen = () => {
    setOpen(true);
  };
  const handleClose = () => {
    setOpen(false);
  };
  const itemData = [
    {
      img: 'https://via.placeholder.com/300',
     title: 'Dialog Image 1',
    },
    {
      img: 'https://via.placeholder.com/300',
      title: 'Dialog Image 2',
    },
  ];
  return (
    <div>
      <Button variant="outlined" onClick={handleClickOpen}>
        打开图像对话框
      </Button>
      <Dialog onClose={handleClose} open={open}>
        <DialogTitle>图像对话框</DialogTitle>
        <ImageList cols={2}>
          {itemData.map((item) => (
            <ImageListItem key={item.img}>
              <img
                src={`${item.img}?w=164&h=164&fit=crop&auto=format`}
                alt={item.title}
                loading="lazy"
              />
            </ImageListItem>
          ))}
        </ImageList>
      </Dialog>
    </div>
  );
}
export default DialogImageListExample;
6. 总结
Material UI 的 Layout Image List 组件提供了一种灵活而美观的方式来展示图像。通过简单的配置,可以实现多种不同的布局效果。结合其他组件,如 Card 和 Dialog,可以构建出更加丰富和交互性强的用户界面。
希望这篇博客能够帮助你更好地理解和使用 Material UI 的 Layout Image List。如果你有任何问题或需要进一步的示例,请随时提问!
              chat评论区
            
            
              评论列表