How to scroll my layout when setting android: windowSoftInputMode = "adjustPan"?

In my activity there is a top panel and a bottom panel. the space between the top panel and the bottom panel I have a linear output with several kinds of edittext inside. Since I do not want my layout to change every time the on-screen keyboard appears, so I set android: windowSoftInputMode = "adjustPan" for my activity in the manifest. But when the soft keyboard is open, I want to scroll down to select another editor for input, this does not allow me to do this. Im only able to select edittext at the bottom when I close the soft keyboard. It is very annoying and uncomfortable. How can I get both scrollview mode and ajustpan for soft keyboard to work well together?

Please help me. thank you very much.

+6
source share
2 answers

Finally, I will find a workaround for my problem, so I want to share with someone who might get the same problem in the future. A brief description of my layout:

<myRelativeLayout> <topbar.../> <myscrollView> <linearLayout> //all stuff controls:editview,textview,.... </linearLayout> </myscrollView> <bottombar.../> 

i create a custom class myRelativeLayout extend RelativeLayout

 public class myRelativeLayout extends RelativeLayout{ public interface OnRelativeLayoutChangeListener { void onLayoutPushUp(); void onLayoutPushDown(); } private OnRelativeLayoutChangeListener layoutChangeListener; public myRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int proposedheight = MeasureSpec.getSize(heightMeasureSpec); final int actualHeight = getHeight(); if (actualHeight > proposedheight){ // Keyboard is shown layoutChangeListener.onLayoutPushUp(); } else if(actualHeight < proposedheight){ // Keyboard is hidden layoutChangeListener.onLayoutPushDown(); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public void setLayoutChangeListener(OnRelativeLayoutChangeListener layoutChangeListener) { this.layoutChangeListener = layoutChangeListener; } public OnRelativeLayoutChangeListener getLayoutChangeListener() { return layoutChangeListener; } 

}

And in my activity, I just set setLayoutChangeListener for myRelativeLayout to hide the narrow harvester when the on-screen keyboard appears and displays the "narrow" block when the hidden keyboard is hidden:

 myRlayout.setLayoutChangeListener(new OnRelativeLayoutChangeListener() { @Override public void onLayoutPushUp() { // TODO Auto-generated method stub myBottombar.setVisibility(View.GONE);//in my case i need to setVisibility(View.GONE) to bottombar in order for this bar is not displayed when softkeyboard show up. } @Override public void onLayoutPushDown() { // TODO Auto-generated method stub myBottombar.setVisibility(View.VISIBLE);// redisplay myBottombar when keyboard is closed. } }); 

Remember to set android: windowSoftInputMode = "adjustResize" for activity. Hope this is helpful for someone getting the same issue.

+4
source

put those EditText in the ScrollView as follows:

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/editText3" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> 
+1
source

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


All Articles