Haha, when you see this title, your JH tightens. You may say that you have never encountered it, but not encountering it now does not mean that you will never encounter it. After all, design is unpredictable. There is nothing you can't realize, only things you can't think of. What effect does it have? Yes, it is a small login page. Everyone has the Lagou app. The login page of Lagou is very smooth and has animation effects, so there is a login effect similar to Lagou, as shown in the figure: Although it is a simple page, it covers quite a lot of things. I wonder why Google has not provided a simple, convenient and accurate keyboard monitoring event? So we can only monitor keyboard events from the side. We can monitor the changes of the outermost layout to determine whether the keyboard has popped up. Without further ado, let's get on the bus. Layout file, everyone can understand it. If we want to monitor keyboard events, we first want to know that we can do something when the keyboard pops up, and then do something else when the keyboard is searched. Knowing this is not enough, we also need to know how much the keyboard pops up and how much distance it needs to be translated. We all know that when a page pops up the keyboard, the root layout of this page will call back its listening method: addOnLayoutChangeListener(); when the keyboard pops up, our layout changes, so this callback method will be executed, but the premise is that the windowSoftInputMode property of our Activity must be set to adjustResize. We want the layout to translate as a whole, which is the distance from the top of the view at the bottom when it pops up minus the height of our keyboard. Now we think that as long as the height of the control pushing the Activity up exceeds 1/3 of the screen height, the soft keyboard is considered to pop up.
In this way, we found that the effect can be achieved, but I want to display it in full screen. I was confused and found that this method is not called back when it is in full screen. What should I do? I checked the information again and found that this is also a bug, but there is a solution, AndroidBug5497Workaround. It is also provided by Google? Copy it directly and you will find that its function is to make the root layout of the outermost layer of the Activity respond to this change when there is a layout change. mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener();
Usage: If we set full screen, we will load it, otherwise it will be ignored:
Next, let's look at the specific animation events. When the keyboard pops up, the whole thing moves upward and the LOGO shrinks. When the keyboard is retracted, the whole thing moves downward and the LOGO returns to its original size. All the attributes used here are animations. Only with attribute animations can we achieve a true translation effect. I see many people online using addOnLayoutChangeListener() to listen for keyboard events, but this method calls back too frequently. For example, in this example, a clear icon is displayed when there is text behind the input box. If you use this method, it will also be executed once, which may affect your animation. Of course, you can also record the height of the first time so that it will not follow the logic, but I don't think it is very reliable. Although my method is not great either๑乛◡乛๑~. *** Paste the source code: If you have any questions, please point them out. I will give you an example address, including another way to achieve the panning effect by sliding the scrollview to the top. |
<<: The fourth session of the Aiti Tribe Technical Clinic
>>: Gradle for Android Part 1 (Starting with Gradle and AS)
I used to think about this question often when I ...
At last year's fall conference, Apple demonst...
Recently, making cassava syrup seems to be popula...
This magical stripe has ruined countless photos, ...
The Internet has entered the second half of its e...
Microsoft IE is about to die. A series of browser...
Although many cars on the market are now equipped...
2021 Short Video Basic Training Camp, learn how t...
[[120519]] Although I have played many games sinc...
First, let me ask a question: How much memory do ...
Today’s topic is how to ignite social communicati...
For the past Humans always have a natural curiosi...
With the deepening development of the smart home ...
The New Year is coming soon There must be a lot o...
New regulations on the payment of one-child allow...