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)
After a website is built, good keywords are very ...
1. Case Background As a rule, before talking abou...
185-6916-1745 WeChat synchronization, high-end ta...
In this article, let’s take a look at how to use ...
The Wandering Earth 2 movie After the space stati...
Do you know what the sun does? Sunlight can bring...
A name that seems to be full of clickbait titles....
There is a magical organ in our body. It is usual...
In an era when true wireless headphones have beco...
I've praised your spam filters before, but I&...
As the traffic dividend gradually weakens and the...
How much does the Lishui driver agency app cost? ...
2014 has gone far away from us. In the past year,...
I want to go out, but when is it safe? Will the e...
Among the many user value analysis models, the RF...