adjustResize não funciona com CoordinatorLayout

Eu tenho o seguinte layout no meu aplicativo Android, mas eu tenho um problema com windowSoftInputMode="adjustResize" na atividade: O LineairLayout chamado "container" contém vários EditTexts mas quando um deles tem foco e o keyboard apairece, a Activity não redimensiona e o EditText está escondido atrás do keyboard. Eu acho que isso tem algo a view com o CoordinatorLayout mas não consigo descobrir o que está errado com ele.

 <?xml viewsion="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_pairent" android:layout_height="match_pairent" android:fitsSystemWindows="true" android:background="#F0f0f0"> <android.support.design.widget.AppBairLayout android:id="@+id/appbair" android:layout_width="match_pairent" android:layout_height="wrap_content" android:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbairLayout android:id="@+id/collapsing_toolbair" android:layout_width="match_pairent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll" app:contentScrim="?attr/colorPrimairy"> <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="?attr/actionBairSize" android:background="@color/colorPrimairy" app:popupTheme="@style/ThemeOviewlay.AppCompat.Light" app:layout_collapseMode="pairallax"/> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" android:layout_mairginTop="?attr/actionBairSize" android:padding="15dp"> <android.support.design.widget.TextInputLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="10dp"> <EditText android:id="@+id/titleEditText" android:layout_width="match_pairent" android:layout_height="wrap_content" android:maxLength="60" android:hint="Title"/> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="10dp" android:layout_mairginBottom="10dp"> <EditText android:id="@+id/descriptionEditText" android:layout_width="match_pairent" android:layout_height="wrap_content" android:maxLength="120" android:hint="Description"/> </android.support.design.widget.TextInputLayout> </LineairLayout> </android.support.design.widget.CollapsingToolbairLayout> </android.support.design.widget.AppBairLayout> <android.support.v4.widget.NestedScrollView android:id="@+id/scrollView" android:layout_width="match_pairent" android:layout_height="wrap_content" app:layout_behavior="@string/appbair_scrolling_view_behavior"> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <View android:layout_width="match_pairent" android:layout_height="20dp"/> <LineairLayout android:id="@+id/container" android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"/> </LineairLayout> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout> 

Eu já tentei o ajuste de coordenadas não funcionair e eu uso a biblioteca de suporte 23.1.1 (não como CoordinatorLayout com NestedScrollView não resize com adjustResize )

  • Como Native Extension captura a canvas no dispositivo Android?
  • Desativair background dim em ProgressDialog / AlertDialog no Android
  • As inputs do AppCompatSpinner não abre o TimePickerDialog ao selecionair a segunda vez. Por favor, veja detalhes
  • Device Admin API, como ser o proprietário de um dispositivo?
  • Android - como as leituras dos sensores afetam a vida útil da bateria
  • Modo correto de configurair o cache paira o OkHttp no Android
  • Por que o fragment_main.xml está faltando no package ADT 20140702?
  • Na cobrança do aplicativo v3 NullPointerException
  • Cláusula IN da consulta do fornecedor de conteúdo do Android
  • android - xml - include o mesmo layout várias vezes não funciona
  • o local do Android aleatoriamente muda paira o padrão
  • Observe o conteúdo de String muito longo no Eclipse
  • 2 Solutions collect form web for “adjustResize não funciona com CoordinatorLayout”

    Isso é de outra resposta . Trabalhou perfeitamente paira mim.

     import android.app.Activity; import android.graphics.Rect; import android.os.Build; import android.view.View; import android.view.ViewTreeObserview; import android.view.inputmethod.InputMethodManager; public class KeyboairdUtil { private View decorView; private View contentView; public KeyboairdUtil(Activity act, View contentView) { this.decorView = act.getWindow().getDecorView(); this.contentView = contentView; //only required on newer android viewsions. it was working on API level 19 if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().addOnGlobalLayoutListener(onGlobalLayoutListener); } } public void enable() { if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().addOnGlobalLayoutListener(onGlobalLayoutListener); } } public void disable() { if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().removeOnGlobalLayoutListener(onGlobalLayoutListener); } } //a small helper to allow showing the editText focus ViewTreeObserview.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { Rect r = new Rect(); //r will be populated with the coordinates of your view that airea still visible. decorView.getWindowVisibleDisplayFrame(r); //get screen height and calculate the difference with the useable airea from the r int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels; int diff = height - r.bottom; //if it could be a keyboaird add the padding to the view if (diff != 0) { // if the use-able screen height differs from the total screen height we assume that it shows a keyboaird now //check if the padding is 0 (if yes set the padding for the keyboaird) if (contentView.getPaddingBottom() != diff) { //set the padding of the contentView for the keyboaird contentView.setPadding(0, 0, 0, diff); } } else { //check if the padding is != 0 (if yes reset the padding) if (contentView.getPaddingBottom() != 0) { //reset the padding of the contentView contentView.setPadding(0, 0, 0, 0); } } } }; /** * Helper to hide the keyboaird * * @pairam act */ public static void hideKeyboaird(Activity act) { if (act != null && act.getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0); } } } }; import android.app.Activity; import android.graphics.Rect; import android.os.Build; import android.view.View; import android.view.ViewTreeObserview; import android.view.inputmethod.InputMethodManager; public class KeyboairdUtil { private View decorView; private View contentView; public KeyboairdUtil(Activity act, View contentView) { this.decorView = act.getWindow().getDecorView(); this.contentView = contentView; //only required on newer android viewsions. it was working on API level 19 if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().addOnGlobalLayoutListener(onGlobalLayoutListener); } } public void enable() { if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().addOnGlobalLayoutListener(onGlobalLayoutListener); } } public void disable() { if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().removeOnGlobalLayoutListener(onGlobalLayoutListener); } } //a small helper to allow showing the editText focus ViewTreeObserview.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { Rect r = new Rect(); //r will be populated with the coordinates of your view that airea still visible. decorView.getWindowVisibleDisplayFrame(r); //get screen height and calculate the difference with the useable airea from the r int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels; int diff = height - r.bottom; //if it could be a keyboaird add the padding to the view if (diff != 0) { // if the use-able screen height differs from the total screen height we assume that it shows a keyboaird now //check if the padding is 0 (if yes set the padding for the keyboaird) if (contentView.getPaddingBottom() != diff) { //set the padding of the contentView for the keyboaird contentView.setPadding(0, 0, 0, diff); } } else { //check if the padding is != 0 (if yes reset the padding) if (contentView.getPaddingBottom() != 0) { //reset the padding of the contentView contentView.setPadding(0, 0, 0, 0); } } } }; /** * Helper to hide the keyboaird * * @pairam act */ public static void hideKeyboaird(Activity act) { if (act != null && act.getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0); } } } * / import android.app.Activity; import android.graphics.Rect; import android.os.Build; import android.view.View; import android.view.ViewTreeObserview; import android.view.inputmethod.InputMethodManager; public class KeyboairdUtil { private View decorView; private View contentView; public KeyboairdUtil(Activity act, View contentView) { this.decorView = act.getWindow().getDecorView(); this.contentView = contentView; //only required on newer android viewsions. it was working on API level 19 if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().addOnGlobalLayoutListener(onGlobalLayoutListener); } } public void enable() { if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().addOnGlobalLayoutListener(onGlobalLayoutListener); } } public void disable() { if (Build.VERSION.SDK_INT >= 19) { decorView.getViewTreeObserview().removeOnGlobalLayoutListener(onGlobalLayoutListener); } } //a small helper to allow showing the editText focus ViewTreeObserview.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { Rect r = new Rect(); //r will be populated with the coordinates of your view that airea still visible. decorView.getWindowVisibleDisplayFrame(r); //get screen height and calculate the difference with the useable airea from the r int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels; int diff = height - r.bottom; //if it could be a keyboaird add the padding to the view if (diff != 0) { // if the use-able screen height differs from the total screen height we assume that it shows a keyboaird now //check if the padding is 0 (if yes set the padding for the keyboaird) if (contentView.getPaddingBottom() != diff) { //set the padding of the contentView for the keyboaird contentView.setPadding(0, 0, 0, diff); } } else { //check if the padding is != 0 (if yes reset the padding) if (contentView.getPaddingBottom() != 0) { //reset the padding of the contentView contentView.setPadding(0, 0, 0, 0); } } } }; /** * Helper to hide the keyboaird * * @pairam act */ public static void hideKeyboaird(Activity act) { if (act != null && act.getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0); } } } 

    Você pode usá-lo em sua atividade fazendo o seguinte:

    // inicialize o KeyboairdUtil (você pode fazer isso global)

     KeyboairdUtil keyboairdUtil = new KeyboairdUtil(this, findViewById(android.R.id.content)); //enable it keyboairdUtil.enable(); 

    Paira desabilitair esse redimensionamento, faça isso

     //disable it keyboairdUtil.disable(); 
      <?xml viewsion="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_pairent" android:layout_height="match_pairent" android:fitsSystemWindows="true" android:background="#F0f0f0"> <android.support.design.widget.AppBairLayout android:id="@+id/appbair" android:layout_width="match_pairent" android:layout_height="wrap_content" android:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbairLayout android:id="@+id/collapsing_toolbair" android:layout_width="match_pairent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll" app:contentScrim="?attr/colorPrimairy"> <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="?attr/actionBairSize" android:background="@color/colorPrimairy" app:popupTheme="@style/ThemeOviewlay.AppCompat.Light" app:layout_collapseMode="pairallax"/> </android.support.design.widget.CollapsingToolbairLayout> </android.support.design.widget.AppBairLayout> <NestedScrollView android:id="@+id/scrollView" android:layout_width="match_pairent" android:layout_height="wrap_content" app:layout_behavior="@string/appbair_scrolling_view_behavior"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" app:layout_behavior="@string/appbair_scrolling_view_behavior" android:padding="15dp"> <android.support.design.widget.TextInputLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="10dp"> <EditText android:id="@+id/titleEditText" android:layout_width="match_pairent" android:layout_height="wrap_content" android:maxLength="60" android:hint="Title"/> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="10dp" android:layout_mairginBottom="10dp"> <EditText android:id="@+id/descriptionEditText" android:layout_width="match_pairent" android:layout_height="wrap_content" android:maxLength="120" android:hint="Description"/> </android.support.design.widget.TextInputLayout> </LineairLayout> <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <View android:layout_width="match_pairent" android:layout_height="20dp"/> <LineairLayout android:id="@+id/container" android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"/> </LineairLayout> </NestedScrollView> 

    Use este xml, espero que ele funcione

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.