How to scroll the layout when the keyboard is visible in action using FULL_SCREEN

I want to scroll my layout when the softinput keyboard is displayed. I defined scrollview in my xml in the right place, but when the keyboard is visible, it hides part of the layout, such as buttons. I read on stackoveflow Link that scrollview does not work when activity is FULL_SCREEN. If this is true, then how can I scroll my layout when softinput is displayed.

+4
source share
2 answers

Use this custom relative layout to detect soft keyboard using ur xml

import android.app.Activity; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.LinearLayout; import android.widget.RelativeLayout; /** * RelativeLayout that can detect when the soft keyboard is shown and hidden. * */ public class RelativeLayoutThatDetectsSoftKeyboard extends RelativeLayout { public RelativeLayoutThatDetectsSoftKeyboard(Context context, AttributeSet attrs) { super(context, attrs); } public interface Listener { public void onSoftKeyboardShown(boolean isShowing); } private Listener listener; public void setListener(Listener listener) { this.listener = listener; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); Activity activity = (Activity)getContext(); Rect rect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight(); int diff = (screenHeight - statusBarHeight) - height; if (listener != null) { listener.onSoftKeyboardShown(diff>128); // assume all soft keyboards are at least 128 pixels high } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 

Then implements RelativeLayoutThatDetectsSoftKeyboard.Listener for your Actiity class

  RelativeLayoutThatDetectsSoftKeyboard mainLayout = (RelativeLayoutThatDetectsSoftKeyboard)V.findViewById(R.id.dealerSearchView); mainLayout.setListener(this); @Override public void onSoftKeyboardShown(boolean isShowing) { if(isShowing) { } else { } } 

Based on keyboard visibility, move the layout up and down using the layout options

+1
source

you need to modify the manifest file

in activity tag

Android: windowSoftInputMode = "adjustPan" add this.

see this http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

0
source

Source: https://habr.com/ru/post/1480893/


All Articles