OK. But how the online wallet(W2) knows whether the new address is produced by the offline one(W1). I could use the online wallet to send transactions even the address and private key are produced by another wallet, for example, BitCore-Qt wallet. Is there any calculation or algorithm behind the checking?
No, you couldn't use an address and private key from another wallet... Electrum HD wallets DO NOT allow you to import private keys. They can only ever hold the keys/addresses generated from your seed.
So, both the online and offline wallet use the same identical Master Public Key. This is the "starting point" for address generation, so both wallets will generate identical lists of addresses... Forever!
Since the new addresses is produced after the Wallet is created, and the gap limit is 20 by default. If I recover from the seed, I think only 20 addresses are produced by default. If you are correct, is that possible the new address is not in the 'address' list by default ? I have to create new addresses and wish it shows up.
The "gap limit" is simply how many consecutive "empty" addresses need to occur before the wallet stops looking for more used addresses after the wallet is restored.
So, if you have used say 14 addresses, and then wipe your computer and restore your wallet... During the restore, it'll find the first 14 addresses have been used... Then it will find 20 empty ones and that triggers the "gap limit" functionally, so it'll stop generating and checking addresses... And you wallet will now have a total of 34 addresses in it.
Also, each time you use an address, Electrum will automatically generate a new address out to the gap limit to maintain a pool of unused addresses.
You should not need to modify the gap limit unless you're constantly generating an enormous amount of addresses and receiving payments to them "out of order"... More likely in an ecommerce setup as opposed to a cold storage scenario