linux创建交换分区设置_如何在Linux上创建交换文件-程序员宅基地

技术标签: python  java  linux  操作系统  大数据  

linux创建交换分区设置

linux创建交换分区设置

The inside of a mechanical hard disk.
zentilia/Shutterstock.com zentilia / Shutterstock.com

Add swap space to a Linux computer, or increase the swap space that’s already present, without messing about with partitions. We show you the easy way to tailor your swap space.

将交换空间添加到Linux计算机,或增加已经存在的交换空间,而无需弄乱分区。 我们向您展示了定制交换空间的简便方法。

交换文件与交换分区 (Swap Files vs. Swap Partitions)

There are several scenarios where you might want to increase existing or add new swap space to your Linux computer.

在几种情况下,您可能希望增加现有空间或向Linux计算机添加新的交换空间。

  • Perhaps your swap space is frequently running at maximum or close to maximum.

    也许交换空间经常以最大或接近最大的速度运行。
  • It’s easy to click the wrong option during the installation process and to decline adding swap to your system inadvertently.

    很容易在安装过程中单击错误的选项,并拒绝在不经意间将交换添加到系统中。
  • Maybe you previously decided that you had so much random access memory (RAM) you didn’t need any swap, and you’ve changed your mind.

    也许您先前认为您有这么多的随机存取存储器 (RAM),不需要进行任何交换,但是您改变了主意。

  • Sometimes you inherit the administration of a system that has no swap, for reasons you’ll never be able to discover.

    有时,由于永远无法发现的原因,您继承了没有交换的系统的管理。

The simple solution to all of these is to add a swap file to your computer. This is a special file, pre-allocated and reserved for use as swap space. A swap file will work in tandem with any existing swap you may have, whether that is a swap file or a swap partition.

所有这些的简单解决方案是将交换文件添加到您的计算机 。 这是一个特殊文件,已预先分配并保留用作交换空间。 交换文件将与您可能拥有的任何现有交换(包括交换文件或交换分区)协同工作。

At one time, there was a performance hit for using a swap file compared to a swap partition. That’s no longer the case with improvements in the performance of mechanical (spinning) hard drives and more efficiency in the swap functions within the Linux operating system. In fact, some Linux distributions now default to creating swap files rather than swap partitions.

一次,与交换分区相比,使用交换文件的性能受到了影响。 机械(旋转)硬盘性能的提高和Linux操作系统中交换功能的更高效率不再是这种情况。 实际上,某些Linux发行版现在默认创建交换文件,而不是交换分区。

Swap isn’t just used as a means to free up RAM when you’re running low on memory. It’s an important part of a well functioning system. Without any swap, sane memory management becomes very difficult for the kernel to achieve. Let’s look at the easy way to add some swap space.

交换不仅仅用于在内存不足时释放RAM。 这是运作良好的系统的重要组成部分。 如果不进行任何交换,则对于内核而言,健全的内存管理将变得非常困难。 让我们看一下添加一些交换空间的简单方法。

在我们深入之前:Btrfs和SSD (Before We Dive In: Btrfs and SSDs)

There are two points we’d like to discuss quickly.

我们想快速讨论两点。

The Btrfs file system has certain caveats about swap files. At one time, there was a conflict between the copy-on-write nature of Btrfs, which wanted to operate in one way and swap files that needed to operate in another. Some functions that swap files depend on were not implemented, and some assumptions that were made about block numbering within the swap files did not hold true with Btrfs. So swap files were not supported.

Btrfs文件系统对交换文件有一些警告。 一次,Btrfs 的写时复制特性(想要以一种方式进行操作)与交换需要以另一种方式进行操作的文件之间存在冲突。 交换文件所依赖的某些功能尚未实现,并且有关交换文件中块编号的某些假设在Btrfs中不成立。 因此不支持交换文件。

Since kernel 5.0, you can have swap files in Btrfs file systems if they are set up with the following requirements:

从内核5.0开始,如果按以下要求设置了交换文件 ,则可以在Btrfs文件系统中拥有它们:

  • No copy-on-write (NOCOW) files.

    没有写时复制(NOCOW)文件。
  • They’re not compressed.

    他们没有被压缩。
  • They don’t straddle different hard drives.

    它们不会跨在不同的硬盘上。

Most readers will be using the default ext4 file system, so this won’t be a concern to them.

大多数读者将使用默认的ext4文件系统 ,因此他们不必担心。

When Solid-State Drives (SSDs) were first available, there was a concern about using them in situations that had frequent file system writes. People were warned off from putting swap space on SSDs, and even to avoid system logging to SSDs.

固态驱动器(SSD)首次可用时,存在着在频繁写入文件系统的情况下使用它们的担忧。 人们被警告不要在SSD上放置交换空间,甚至避免将系统记录到SSD。

This is much less of a concern nowadays, and many SSDs that are on sale have life expectancies that will outlast most PCs. A swap file on an SSD will have a far better performance than a swap partition on a mechanical hard drive.

如今,这已不再是一个令人担忧的问题,而且许多正在销售的SSD的预期寿命将比大多数PC都要长 。 SSD上的交换文件比机械硬盘上的交换分区具有更好的性能。

检查现有交换空间 (Checking Existing Swap Space)

Look before you leap. Let’s check what swap space is available on your computer. You can do this two ways, and we’ll use both. The free command will display the used and free memory. The -h (human readable) option will cause free to use sensible units when it displays the memory values.

三思而后行。 让我们检查一下计算机上可用的交换空间。 您可以通过两种方式执行此操作,我们将同时使用这两种方式。 free命令将显示已用和可用的内存-h (人类可读)选项在显示内存值时将导致free使用明智的单位。

free -h
fre -h  in a terminal window

The output from free shows that there is no swap space configured on this machine.

free的输出表明该机器上没有配置交换空间。

Swap is never discussed without RAM and free RAM cropping up. So it’s worth noting that the free RAM is given as 237 MB. Don’t mistake that for the total of RAM available for use. That value is provided by the “available” figure, which is 881 MB.

没有RAM和可用RAM的出现,绝不会讨论交换。 因此,值得注意的是,可用RAM为237 MB。 不要误以为可用的RAM总量。 该值由“可用”数字提供,为881 MB。

Linux uses free RAM for its own purposes, such as file caching and kernel buffers. The amount of RAM dedicated to that is the “buff/cache” figure, which is 871 MB. But that memory is still regarded as—and counted as—“available.” The contents of the “buf/cache” RAM can be discarded immediately and used by any application that needs some memory.

Linux将空闲的RAM用于自己的目的,例如文件缓存和内核缓冲区。 专用于此的RAM数量是“ buff / cache”数字,为871 MB。 但是,该内存仍被视为(并算作)“可用”。 “ buf / cache” RAM的内容可以立即丢弃,并可由需要内存的任何应用程序使用。

Another way to check if swap space is available is to use the swapon command. The --show option doesn’t make any changes to the swap on your computer. It only provides statistics.

检查交换空间是否可用的另一种方法是使用swapon命令。 --show选项不会对计算机上的交换进行任何更改 。 它仅提供统计信息。

swapon --show
swapon --show in a terminal window

If there is no output from this command, there’s no swap configured.

如果此命令没有输出,则没有配置交换。

If these commands had revealed some swap space is already configured, the size of the existing swap space should be factored into decisions regarding the size of the swap file you’re going to create.

如果这些命令表明已经配置了一些交换空间,则应在决定要创建的交换文件大小时考虑现有交换空间的大小。

我需要多少交换空间? (How Much Swap Space Do I Need?)

The traditional response was “twice the amount of RAM you have.” But this was coined when computers used to have very limited RAM. As RAM has become cheaper, and programs and games more demanding of memory, PC specifications have adjusted accordingly. Home PCs with 32 GB of RAM are not uncommon nowadays. And you’re not going to allocate 64 GB of hard drive space to swap space if you’ve got 32 GB of RAM. That’s plainly excessive.

传统的响应是“将您的RAM数量增加两倍”。 但这是在计算机过去具有非常有限的RAM时创造出来的。 随着RAM变得越来越便宜,程序和游戏对内存的要求越来越高,PC规格也相应地进行了调整。 如今,具有32 GB RAM的家用PC并不少见。 如果您有32 GB的RAM,则不会分配64 GB的硬盘驱动器空间来交换空间。 显然太过分了。

The amount of swap you need is as an incendiary subject, comparable to “which is the best editor.” One of the most sensible discussions we’ve seen on this topic is in the Ubuntu swap FAQ. It’s a short and commonsense approach (although, like many people, they misunderstand how swappiness works on Linux). There’s a handy table that shows a recommended amount of swap space for the amount of RAM your system has, and whether you hibernate your computer or not.

您需要的交换数量是一个燃烧的主题,相当于“这是最好的编辑器”。 关于此主题的最明智的讨论之一是Ubuntu交换常见问题解答 。 这是一种简短且常识的方法(尽管像许多人一样,他们误解了swappiness在Linux上的工作原理 )。 有一个方便的表格,其中显示了建议的交换空间,以表示系统具有的RAM量,以及是否使计算机Hibernate。

And the good news is, it doesn’t really matter what value you pick. We can always remove a swap file and replace it with a bigger one or, for that matter, a smaller one. Or you could just add another swap file.

好消息是,选择什么值并不重要。 我们总是可以删除一个交换文件,并用一个较大的文件或一个较小的文件替换它。 或者,您可以仅添加另一个交换文件。

Pick a swap file size from the table, and run it for a while. Monitor your system’s use of the swap space. If fine-tuning is required, changes are easily made. With swap files, It’s a two-minute job. Compare that to adjusting partitions on a live Linux computer.

从表中选择一个交换文件大小 ,然后运行一段时间。 监视系统对交换空间的使用。 如果需要微调,则可以轻松进行更改。 使用交换文件,这是两分钟的工作。 将其与调整实时Linux计算机上的分区进行比较。

创建交换文件 (Creating the Swap File)

You shouldn’t use the fallocate command to create your swapfile. This is from the man page for swapon:

您不应该使用fallocate命令来创建交换文件 。 这是来自swapon的手册页:

The swap file implementation in the kernel expects to be able to write to
the file directly, without the assistance of the file system. 

This is a problem on files with holes or on copy-on-write files on file 
systems like Btrfs. Commands like cp(1) or truncate(1) create files with 
holes. These files will be rejected by swapon. 

Preallocated files created by fallocate(1) may be interpreted as files 
with holes too depending of the filesystem. Preallocated swap files are 
supported on XFS since Linux 4.18. 

The most portable solution to create a swap file is to use dd(1) and 
/dev/zero.

So, although fallocate is faster, we’ll use dd to create the swap file. The machine used to research this article has two GB of RAM. We’re going to create a one GB swap file.

因此,尽管fallocate速度更快,但我们将使用dd 创建交换文件 。 用于研究本文的计算机具有两个GB的RAM。 我们将创建一个1 GB的交换文件。

The options are:

选项包括:

  • if: The input file. In this example, we’re using /dev/zero which will provide a stream of zero bytes.

    if :输入文件。 在此示例中,我们使用/dev/zero ,它将提供零字节流。

  • of: The output file. We’re going to create a file in the root directory, called swapfile.

    of :输出文件。 我们将在根目录中创建一个名为swapfile

  • bs: The block size in bytes. This specifies how many bytes to read from the input file and to write to the output file, at a time.

    bs :块大小(以字节为单位)。 这指定一次要从输入文件读取并写入输出文件的字节数。

  • count: How many blocks to read and write. Multiply this number by the bs value to get the file size.

    count :要读写的块 。 将此数字乘以bs值即可得到文件大小。

sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576 in a terminal window

Some statistics are provided when the file is created.

创建文件时会提供一些统计信息。

output from sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576 in a terminal window

We can see the number of blocks (records) that were written to the file, the size of the file, the time taken to create the file, and the effective data transfer rate.

我们可以看到写入文件的块(记录)数,文件大小,创建文件所花费的时间以及有效数据传输率。

Use the ls command to see the file in the root directory:

使用ls命令查看根目录中的文件:

ls /
ls / in a terminal window

准备交换文件 (Preparing the Swap File)

We need to prepare the swap file with the mkswap command before it can be used. We don’t need to provide any parameters to mkswap other than the path and name of the file:

我们需要先使用mkswap命令准备交换文件 ,然后才能使用它。 除了文件的路径和名称之外,我们不需要为mkswap提供任何参数:

sudo mkswap /swapfile
sudo mkswap /swapfile in a terminal window

The file is prepared for use as a swap file. Note the warning about file permissions. We’ll need to change those so that the root user is the only one who can read and write to the swap file.

该文件已准备好用作交换文件。 请注意有关文件权限的警告。 我们需要更改这些设置,以便root用户是唯一可以读写交换文件的用户。

使用交换文件 (Using the Swap File)

The default permissions are too liberal, we need to restrict them so that only root can use the swapfile. Use chmod to change the file permissions:

默认权限太宽松了,我们需要限制它们,以便只有root才能使用swapfile。 使用chmod更改文件权限

sudo chmod 600 /swapfile
sudo chmod 600 /swapfile in a terminal window

This removes all permissions from the file group members and others, but allows the file owner, root, to read and write to the file.

这将删除文件组成员和其他成员的所有权限,但允许文件所有者(根)读取和写入文件。

We need to use the swapon command to let Linux know there is a new swap file available to use. We only need to provide the path and the filename:

我们需要使用swapon命令让Linux知道有一个新的交换文件可供使用。 我们只需要提供路径和文件名:

sudo swapon /swapfile
sudo swapon /swapfile in a terminal window

The swap file is now active.

交换文件现在处于活动状态。

将交换文件添加到fstab (Adding the Swap File to fstab)

To make sure your swap file is available after a reboot, add it to the /etc/fstab file. You can use any text editor you prefer, but we’ll show the process using the graphical Gedit text editor.

为确保交换文件在重启后可用, 请将其添加到/etc/fstab文件中 。 您可以使用自己喜欢的任何文本编辑器,但是我们将使用图形化的Gedit文本编辑器显示该过程。

sudo gedit /etc/fstab
sudo gedt /etc/fstab in a terminal window

The line we need to add to the bottom of the file is:

我们需要添加到文件底部的行是:

/swapfile    none    swap    sw    0    0
/etc/fstab with the swapfile entry highlighted

The fields are:

字段是:

  • File system: The path and name of the swap file.

    文件系统 :交换文件的路径和名称。

  • Mount point: The file isn’t mounted like a file system, so the entry is “none.”

    挂载点 :文件的挂载方式不像文件系统那样,因此条目为“ none”。

  • Type: This is “swap.”

    类型 :这是“交换”。

  • Options: At boot time swapon -a (start all devices marked as swap) will be called from one of the boot scripts. This option tells Linux to treat this entry as a swap resource that should come under the control of that swapon -a command. It is common to see “defaults” used here because there is a mistaken belief amongst some Linux users that this field is ignored. As we shall see, that is not the case. So it makes sense to use the correct option.

    选项 :在引导时, swapon -a (启动所有标记为swap的设备)将从一个引导脚本中调用。 此选项告诉Linux将此项视为交换资源,应在该swapon -a命令的控制之下。 经常在这里看到“默认值”是因为一些Linux用户错误地认为此字段被忽略了。 我们将看到,事实并非如此。 因此,使用正确的选项很有意义。

  • Dump: This can be set to zero. It is irrelevant in this case.

    转储 :可以设置为零。 在这种情况下无关紧要。

  • Pass: This can be set to zero. It is irrelevant in this case.

    通过 :可以设置为零。 在这种情况下无关紧要。

Save the changes and close the editor.

保存更改并关闭编辑器。

检查交换使用情况 (Checking Swap Usage)

To see if your swap space is being used, use the swapon command with the --show option:

要查看是否正在使用交换空间,请使用带有--show选项的swapon命令:

swapon --show
swapon --show in a terminal window

The columns are:

这些列是:

  • Name: The name of the swap partition or swap file.

    名称 :交换分区或交换文件的名称。

  • Type: The type of swap device.

    类型 :交换设备的类型。

  • Size: The size of the swap resource.

    大小 :交换资源的大小。

  • Used: The amount of used swap space.

    已用 :已使用的交换空间量。

  • Prio: The priority of this swap space.

    Prio :此交换空间的优先级。

交换空间优先级 (The Swap Space Priority)

Each swap space is allocated a priority. If you don’t provide one, one is automatically allocated. Automatically allocated priorities are always negative.  The range of priorities that can be manually allocated is 0 to 32767. Swap resources with higher priorities are used first.

每个交换空间都分配了一个优先级。 如果您不提供,则会自动分配一个。 自动分配的优先级始终为负。 可以手动分配的优先级范围是0到32767。优先级高的交换资源将首先使用。

If more than one swap space has the same priority they are used alternately until they are both full, then the system looks for the swap space with the next lowest priority. If you only have a single swap space then the priority is irrelevant of course. But we’ll change the priority of the swapfile we’ve created to demonstrate how to do it.

如果多个交换空间具有相同的优先级,它们会交替使用,直到它们都已满,然后系统会寻找具有次低优先级的交换空间。 如果只有一个交换空间,则优先级当然是无关紧要的。 但是,我们将更改为演示如何创建交换文件而设置的优先级。

To set a priority, add the  pri=  (priority) option to the /etc/fstab entry. Edit the line you added to /etc/fstab to look like this:

要设置优先级,请将pri= (优先级)选项添加到/etc/fstab条目中。 编辑添加到/etc/fstab ,如下所示:

/swapfile    none    swap    sw,pri=10    0    0

That is, add pri=10 to the options field, separated from the “sw” with a comma. Do not leave any spaces between the “sw”, the comma, and the “pri=10.” Reboot your computer and use the swapon --show command:

也就是说,将pri=10添加到选项字段,并用逗号将其与“ sw”分开。 在“ sw”,逗号和“ pri = 10”之间不要留任何空格。 重新启动计算机,然后使用swapon --show命令:

swapon -- show
swapon -- show in a terminal window

The priority of this swap space has been elevated to 10. Which is proof positive that the options field in the /etc/fstab entry is not ignored.

该交换空间的优先级已提高到10。这证明了/etc/fstab条目中的options字段未被忽略。

交换空间变得简单 (Swap Space Made Easy)

Cutting through the exposition and explanation, we can create a new swap file as easily and quickly as this:

通过阐述和解释,我们可以像这样轻松而快速地创建一个新的交换文件:

sudo dd if=/dev/zero /of=/swapfile2 bs=1024 count=104857
sudo mkswap /swapfile2
sudo chmod 600 /swapfile2
sudo swapon /swapfile2

And let’s check that it worked:

让我们检查一下它是否有效:

swapon --show
sudo dd if=/dev/zero /of=/swapfile2 bs=1024 count=104857 in a terminal window

If you want to make that permanent drop, it into your /etc/fstab file.

如果要永久删除,请将其放入/etc/fstab文件中。

Boom. Job done.

繁荣。 任务完成。

翻译自: https://www.howtogeek.com/455981/how-to-create-a-swap-file-on-linux/

linux创建交换分区设置

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/culiuman3228/article/details/108788003

智能推荐

BAT批处理创建文件桌面快捷方式_批处理创建桌面快捷方式-程序员宅基地

文章浏览阅读1.5w次,点赞9次,收藏26次。简介一个创建某个文件到桌面快捷方式的BAT批处理.代码@echooff::设置程序或文件的完整路径(必选)setProgram=D:\Program Files (x86)\格式工厂.4.2.0\FormatFactory.exe::设置快捷方式名称(必选)setLnkName=格式工厂v4.2.0::设置程序的工作路径,一般为程序主目录,此项若留空,脚本将..._批处理创建桌面快捷方式

射频识别技术漫谈(6-10)_芯片 ttf模式-程序员宅基地

文章浏览阅读2k次。射频识别技术漫谈(6-10),概述RFID的通讯协议;射频ID卡的原理与实现,数据的传输与解码;介绍动物标签属性与数据传输;RFID识别号的变化等_芯片 ttf模式

Python 项目实战 —— 手把手教你使用 Django 框架实现支付宝付款_django 对接支付宝接口流程-程序员宅基地

文章浏览阅读1.1k次。今天小编心血来潮,为大家带来一个很有趣的项目,那就是使用 Python web 框架 Django 来实现支付宝支付,废话不多说,一起来看看如何实现吧。_django 对接支付宝接口流程

Zabbix 5.0 LTS在清理历史数据后最新数据不更新_zabbix问题没有更新-程序员宅基地

文章浏览阅读842次。Zabbix 5.0 LTS,跑了一年多了一直很稳定,前两天空间显示快满了,于是手贱清理了一下history_uint表(使用mysql truncate),结果折腾了一周。大概故障如下:然后zabbix论坛、各种群问了好久都没解决,最后自己一番折腾似乎搞定了。初步怀疑,应该是由于历史数据被清空后,zabbix需要去处理数据,但是数据量太大,跑不过来,所以来不及更新了(?)..._zabbix问题没有更新

python学习历程_基础知识(2day)-程序员宅基地

文章浏览阅读296次。一、数据结构之字典 key-value

mybatis-plus字段策略注解strategy_mybatisplus strategy-程序员宅基地

文章浏览阅读9.7k次,点赞3次,收藏13次。最近项目中遇到一个问题,是关于mybatis-plus的字段注解策略,记录一下。1问题调用了A组件(基础组件),来更新自身组件的数据,发现自己组件有个字段总是被清空。2原因分析调用的A组件的字段,属于基础字段,自己业务组件,对这个基础字段做了扩展,增加了业务字段。但是在自己的组件中的实体注解上,有一个注解使用错误。mybatis-plus封装的updateById方法,如果..._mybatisplus strategy

随便推点

信息检索笔记-索引构建_为某一文档及集构件词项索引时,可使用哪些索引构建方法-程序员宅基地

文章浏览阅读3.8k次。如何构建倒排索引,我们将这个过程叫做“索引构建”。如果我们的文档很多,这样索引就一次性装不下内存,该如何构建。硬件的限制 我们知道ram读写是随机的操作,只要输入相应的地址单元就能瞬间将数据读出来或者写进去。但是磁盘不行,磁盘必须有一个寻道的过程,外加一个旋转时间。那么只有涉及到磁盘,我们就可以考虑怎么节省I/O操作时间。【注】操作系统往往以数据块为单位进行读写。因为读一_为某一文档及集构件词项索引时,可使用哪些索引构建方法

IT巨头英特尔看好中国市场前景-程序员宅基地

文章浏览阅读836次。英特尔技术与制造事业部副总裁卞成刚7日在财富论坛间隙接受中新社记者采访时表示,该公司看好中国市场前景,扎根中国并以此走向世界是目前最重要的战略之一。卞成刚说,目前该公司正面临战略转型,即从传统PC服务领域扩展至所有智能设施领域,特别是移动终端。而中国目前正引领全球手机市场,预计未来手机、平板电脑等方面的发明创新将大量在中国市场涌现,并推向全球。持相同态度的还有英特尔中国区执行董事戈峻。戈峻

ceph中的radosgw相关总结_radosgw -c-程序员宅基地

文章浏览阅读627次。https://blog.csdn.net/zrs19800702/article/details/53101213http://blog.csdn.net/lzw06061139/article/details/51445311https://my.oschina.net/linuxhunter/blog/654080rgw 概述Ceph 通过radosgw提供RES..._radosgw -c

前端数据可视化ECharts使用指南——制作时间序列数据的可视化曲线_echarts 时间序列-程序员宅基地

文章浏览阅读3.7k次,点赞6次,收藏9次。我为什么选择ECharts ? 本周学校课程设计,原本随机佛系选了一个51单片机来做音乐播放器,结果在粗略玩了CN-DBpedia两天后才回过神,课设还没有开始整。于是懒癌发作,碍于身上还有比赛的作品没交,本菜鸡对硬件也没啥天赋,所以就直接把题目切换成软件方面的题目。写python的同学选择了一个时间序列数据的可视化曲线程序设计题目,果真python在数据可视化这一点性能很优秀。..._echarts 时间序列

ApplicationEventPublisherAware事件发布-程序员宅基地

文章浏览阅读1.6k次。事件类:/** * *   * @className: EarlyWarnPublishEvent *   * @description:数据风险预警发布事件 *   * @param: *   * @return: *   * @throws: *   * @author: lizz *   * @date: 2020/05/06 15:31 * */public cl..._applicationeventpublisheraware

自定义View实现仿朋友圈的图片查看器,缩放、双击、移动、回弹、下滑退出及动画等_imageview图片边界回弹-程序员宅基地

文章浏览阅读1.2k次。如需转载请注明出处!点击小图片转到图片查看的页面在Android开发中很常用到,抱着学习和分享的心态,在这里写下自己自定义的一个ImageView,可以实现类似微信朋友圈中查看图片的功能和效果。主要功能需求:1.缩放限制:自由缩放,有最大和最小的缩放限制 2居中显示:.若图片没充满整个ImageView,则缩放过程将图片居中 3.双击缩放:根据当前缩放的状态,双击放大两倍或缩小到原来 4.单指_imageview图片边界回弹