Android scroll down

I have a text area and a down button and a cancel button. when I click on the keyboard of the text area and focus on the text area, and the buttons are hidden behind the keyboard.

I need it when the text area closes the focus a bit and also displays the bottom buttons when the text area identifier is selected.

+4
source share
3 answers

i fixed it myself: D following code

I called the following method when a text field gets focus

private final void focusOnButtons(){ new Handler().postDelayed(new Runnable() { @Override public void run() { ScrollView sv = (ScrollView)findViewById(R.id.scrl); sv.scrollTo(0, sv.getBottom()); } },1000); } 
+8
source

You can try wrapping your existing layout in a ScrollView:
https://developer.android.com/reference/android/widget/ScrollView.html
Your layout xml file might look like this:

 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView01" android:layout_width="wrap_content" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <EditText android:text="@string/hello" android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"> </EditText> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:text="@+id/Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <Button android:text="@+id/Button02" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> </LinearLayout> </LinearLayout> </ScrollView> 

Comment Commentary:
You can check this page:
https://developer.android.com/training/keyboard-input/index.html

I think the results you want can be accomplished by moving the buttons outside of Scrollview and setting android:windowSoftInputMode="adjustResize" in action.

+4
source

I would edit a few things from the solution:

1.- Put smoothScroll instead of hard scrolling

2.- Reduce the delay from 1000 to 300 (enough)

  OnFocusChangeListener onFocus = new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { new Handler().postDelayed(new Runnable() { @Override public void run() { scrollView.smoothScrollTo(0, scrollView.getBottom()); } },300); } }; 
0
source

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


All Articles