Android-UI-About View-A solution for the toolbar and ScrollView to exist at the same time and the soft keyboard to block the Edittext in the ScrollView

Problem Description

Some time ago, I encountered a difficult situation when I was busy recruiting new apps in the studio. Describe the layout of the problem:

<RelativeLayout ...>
    <ImageView.../>  <!--这三个控件可以可以看成一个toolbar-->
    <ImageView.../>  <!--工作室的图案,名称之类的,需要一直保持在这个位置-->
    <TextView.../>
    <ScrollView>    <!--ScrollView在上面上个控件之下-->
        <Edittext.../>   <!--接下来是好几个Edittext,多到必须用ScrollView滑动才能看完-->
        <Edittext.../>
        <Edittext.../>
        <Edittext.../>
    </ScrollView>
</RelativeLayout>

The requirement is that when you click on Edittext, the screen needs to move to the location of the Edittext (the top three controls must remain in their original positions and remain unchanged), and the soft keyboard cannot be blocked.

methods to try

  • The first thing that comes to mind is to set the android:windowSoftInputMode=”adjustPan” property for the corresponding Activity in the Manifest, but the three controls above the ScrollView will be squeezed out of the screen together, and the effect is very ugly.

  • After the above method fails, I tried to monitor the relative position of the clicked Edittext on the screen, calculate the distance that the ScrollView needs to move, and use the scrollTo method of the ScrollView to manually move to the target position (this method is a bit stupid), but it is too complicated , and ultimately did not adopt.

  • Google, Bing's other approaches are all over the place.

Solution

  1. Set the android:fitsSystemWindows=”true” attribute to the RelativeLayout.
  2. Set android:overScrollMode=”never” to ScrollView.
  3. Set the android:windowSoftInputMode=”stateUnchanged|adjustResize|stateHidden” property for the Activity in the Manifest.
  4. Problem solved, I can finally work on the next project (╯‵□′)╯︵┻━┻

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325748508&siteId=291194637