Android implements the solution of putting the layout on top and the login button on top when the input method pops up

Background: when writing the login interface, the boss felt that the input method soft keyboard talked about when entering the password blocked the login button (as shown in the figure below, it's not cool). Even the input box was blocked by half, so he was dissatisfied and asked me to change it. So I looked at the login effect of QQ, I went to study it and pop up the whole layout of the input method, Finally satisfied the boss.

(as shown in the figure above, the boss is not satisfied, hehe)

1. Let's solve the problem.

I read a lot of blogs and Q & A. many people said that setting < activity Android: windowsoftinputmode = "statevisible|adjustpan"... > for this activity directly in androidmanifest.xml is easy. Whether this is funny or not, it is not obvious that the whole layout moves upward. Anyway, mine is not easy to use. I don't know how those bloggers make it easy. However, looking at the comments, many people say it's difficult to use. Then make a code that everyone can use. Look at the effect first.

Ha ha, did you see that even the login button ran up together. It should be on the top. The boss no longer has to worry about the login button being overwritten.

Then let's go to the code: there are not many codes. It's all in the layout, which can be solved.

The above is all the line of sight codes. A Scrollview outside contains a LinearLayout and three linearlayouts in the middle. Of course, any container control can be included, but it must be constrained by layout_weight. This is the key point. I only said it once. Also, wrap should be used as much as possible for the internal layout of LinearLayout_ Content, even if you want to fix the height properly, just adjust it.

It is very simple to use. There is only the above section of layout. However, there is no need to set this activity in Shenma androidmanifest.xml

For this code, if there is an input box at the bottom (preferably wrapped with FrameLayout), it can be moved upward, similar to QQ input box. Scrollview is not required, and when the input box scrolls up, the whole layout will not scroll up.

2. Finally, another idea is provided. This idea comes from the "roll skin". The login effect of the roll skin. His design idea is that when I click the EditText input box, my first guess is that I get the EditText input focus, or that after listening to the pop-up focus on the keyboard, the background on the top of the roll skin will slowly reduce and hide it, This causes the following two input boxes to scroll to the top, which is convenient for users to enter. This idea also solves the problem that users can input directly.

3. At present, the solution to this problem in many projects is to reduce the logo gradually, and then scroll up as shown in the solution 2 above.

The editor of CSDN is getting worse and worse. I can't get the pictures

Look at the layout:

Then the Java code is,

This code is basically implemented in this way. It can dynamically handle the problem of sroll scrolling up, and the logo can be dynamically reduced

summary

The above is the solution that Xiaobian introduced to you to top up the layout and login button when the Android implementation input method pops up. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>