[Android] prevents UI interfaces from being blocked by input methods (images are adaptive with input methods)

Source: Internet
Author: User

Friends who have used Android phones know that, sometimes, after entering text in the text box, the operation button is blocked by the input method, and they have to close the input method to continue the operation.

For example:

Screen layout:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Id = "@ + ID/ll2" Android: orientation = "vertical" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <br/> <checkbox Android: id = "@ + ID/widget57" Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" Android: TEXT = "@ string/location" <br/> Android: layout_gravity = "right"> <Br/> </checkbox> <br/> <edittext Android: Id = "@ + ID/widget34" Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" Android: layout_weight = "1" <br/> Android: textcolorhighlight = "# cccccc" Android: hint = "what do you want to say? "<Br/> Android: gravity =" TOP "Android: textsize =" 18sp "> <br/> </edittext> <br/> <button Android: id = "@ + ID/widget53" Android: layout_width = "100px" <br/> Android: layout_height = "wrap_content" Android: TEXT = "@ string/share" <br/> Android: layout_gravity = "right"/> <br/> </linearlayout> <br/> 

If you do not perform any operations, click the text box and the effect is:

In this case, the [Share] button is blocked by the input method. You must disable the input method to perform the operation.

Some may say that you can add a scrollview outside the layout. In this way, the UI layout is separated from the input method. After the input method appears, it can also be rolled over.

But is this good? Let's take a look at the effect (layout and scrollview effect ):

Screen layout:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <scrollview xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" <br/> Android: orientation = "vertical"> <br/> <linearlayout <br/> Android: Id = "@ + ID/ll2" Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <br/> <checkbox Android: Id = "@ + ID/widget57" Android: Layout _ Width = "wrap_content" <br/> Android: layout_height = "wrap_content" Android: text = "@ string/location" <br/> Android: layout_gravity = "right"> <br/> </checkbox> <br/> <edittext Android: Id = "@ + ID/widget34" Android: layout_width = "fill_parent" <br/> Android: layout_height = "400px" Android: layout_weight = "1" <br/> Android: textcolorhighlight = "# cccccc" Android: hint = "what do you want to say? "<Br/> Android: gravity =" TOP "Android: textsize =" 18sp "> <br/> </edittext> <br/> <button Android: id = "@ + ID/widget53" Android: layout_width = "100px" <br/> Android: layout_height = "wrap_content" Android: TEXT = "@ string/share" <br/> Android: layout_gravity = "right"/> <br/> </linearlayout> <br/> </scrollview> 

As you can see, there is a scroll bar on the right of the above part. You can scroll down to click the button. However, I personally think it is better to simply close the input method and click the button!

Is there any better way? The answer is yes!

Let's take a look at the effect of this better method:

We can see that the UI layout is also separated from the input method, and the edittext area is automatically reduced. In this case, user input and further operations are not affected!

Even if the input method is enabled, the user can see the overall UI, Which is comfortable and friendly.

Let's talk about how this effect is achieved.

In fact, the answer is very simple. Instead of modifying a local file, you need to modify the androidmanifest. xml file and add one in the activity attribute:

Android: windowsoftinputmode = "adjustresize" 

Comparison before and after androidmanifest. xml modification:

There are other values for this attribute. You can check it online. (Here to give a link: http://blog.csdn.net/liluo1217/archive/2011/02/14/6184169.aspx)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.