Window Soft Input Mode ConstraintLayout

前端 未结 3 1474
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 02:12

Earlier there was no problem with soft input mode, but after including ConstraintLayout, content of fragment doesn\'t move up when the keyboard appears.

Man

相关标签:
3条回答
  • 2021-02-04 02:31

    I encountered the same problem with you, we declared android:windowSoftInputMode="stateAlwaysHidden|adjustResize" in the AndroidManifest.xml, but in fact the App showed the results like adjustPan, the contents are gone on top of the soft keyboard. So I set adjustResize programmatically, successfully solved this problem:

    Just add this line to your onCreate:

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    
    0 讨论(0)
  • 2021-02-04 02:39

    I'm not sure in what Activity your fragment is located but if it's in for example InitChatActivity, just add adjustResize to your manifest, and wrap your ConstraintLayout in ScrollView or NestedScrollView:

    android:windowSoftInputMode="stateHidden|adjustResize"
    
    0 讨论(0)
  • 2021-02-04 02:44

    Everything actually works as intended with the way your layout is built -- margins are fixed distances, so your UI is simply too tall for the smaller screen. You would need to modify your layout to better adapt for a small layout -- either marking unnecessary views (e.g. the logo) as gone (ConstraintLayout will consider "gone" views as collapsed to a single point, in essence -- so the layout still works), or change some margins dimensions to a smaller value.

    The usual way to build this is to use bias constraints or guidelines, instead of hard margins. Using bias or guidelines (in percent mode) would allow you to have more of a "spring"-like behaviour to react better to dimension changes. Typically a layout will be a mix of hard margins and bias / guidelines.

    To sum up, your options are:

    • change the layout to use bias / guidelines (percent) constraints to have a more responsive layout
    • mark some views as GONE when detecting the keyboard
    • change some other values on the fly (font size, margin values...)
    • or, create another layout file for handling this case
    0 讨论(0)
提交回复
热议问题