Why does the keyboard overlap in AutoCompleteTextView when inside ScrollView

I have a simple Android form and code, but the keyboard always overlaps my AutoCompleteTextView when I click on it. Note: AutoCompleteTextView when inside ScrollView. Note: platform 6.0.1

 package com.example.jason_wu.search; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.AutoCompleteTextView; public class Main2Activity extends AppCompatActivity { private AutoCompleteTextView mAtv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); mAtv = (AutoCompleteTextView) findViewById(R.id.location_auto_complete); //issue 1 //mAtv.setBackground(getDrawable(R.drawable.search_input_focus)); //issue 2 mAtv.setHeight(300); } } 

and my AndroidManifest.xml is here:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jason_wu.search"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name="com.example.jason_wu.search.Main2Activity" android:windowSoftInputMode="adjustPan" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 


Layout.xml:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/scrollView" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="800dp" android:text="Large Text" android:id="@+id/textView"/> <AutoCompleteTextView android:id="@+id/location_auto_complete" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_below="@+id/textView" android:background="@color/transparent" android:dropDownAnchor="@+id/location_auto_complete" android:dropDownHeight="wrap_content" android:dropDownVerticalOffset="1dip" android:fontFamily="sans-serif-light" android:hint="@string/new_notification_location_hint" android:imeOptions="actionSearch" android:inputType="textUri" android:dropDownSelector="@color/location_bg_select" android:popupBackground="@color/location_bg_notselect" android:singleLine="true" android:textColor="#FFFFFF" android:alpha="0.2" android:textColorHint="#999999" android:textCursorDrawable="@null" android:textSize="15sp" /> <TextView android:layout_width="wrap_content" android:layout_height="100dp" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Large Text" android:id="@+id/textView2" android:layout_below="@+id/location_auto_complete" /> </RelativeLayout> </ScrollView> </RelativeLayout> 

Cm. issue 2

+6
source share
3 answers

Keyboard behavior is to scroll the view to close the bottom of the text area.

Finally, we should use the android:gravity="bottom" attribute to solve the problem with the UI, but we need to consider UX, ex: Hint.

So, the solution is to listen onClick() and for a keyboard problem, we must use the dynamic method to set the gravity.

0
source

Try to limit the dropdowns to show

One way - you can limit the dropdown items to display. But there is no such right way to show the number of options maximumSuggestions. But the trick you can apply is to get the height of one of the lines and multiply it (the number of lines to display) and use setDropDownHeight() to set its height.

There is a setDropDownHeight AutoCompleteTextView method. You can see them and use.

If you are confused or unsure of the height of the offers, you can customize this. See how to set custom height.

+2
source

try this attribute for activity in AndroidManifest.xml

 android:windowSoftInputMode="stateHidden|adjustPan" 

it should look something like this.

  <activity android:name="com.myexample.TestActivity" android:label="@string/login_screen" android:screenOrientation="portrait" // well you can change the orientation if you want android:windowSoftInputMode="stateHidden|adjustPan" /> 

the attribute you want to play with is windowSoftInputMode to try different values, as you may need a different output after a certain time.

 adjustPan 

The main operation window does not change to make room for a soft keyboard. Rather, the contents of the window automatically expand so that the current focus is never hidden by the keyboard, and users can always see what they are typing. This is generally less desirable than resizing, as the user may need to close the soft keyboard to receive and interact with the shaded parts of the window.

 adjustResize 

The main activity window always changes to make room for the on-screen keyboard.

 stateHidden 

The soft keyboard is hidden when the user selects an action, that is, when the user positively moves forward to activity, and does not access it due to the abandonment of another action.

You can find more information on activity item documentation.

Update

I wrote something that can help you, the layout is available on layout

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="activities.list.first.TestLayoutActivity"> <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.6" android:orientation="vertical"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.4" android:orientation="vertical"> <AutoCompleteTextView android:id="@+id/TestLayoutActivity_autoCompleteTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:completionThreshold="1" android:drawableLeft="@android:drawable/ic_menu_search" android:text="" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout> </LinearLayout> </ScrollView> </LinearLayout> 

AndroidManifest.xml

  <activity android:name="activities.list.first.TestLayoutActivity" android:label="@string/title_activity_test_layout" android:windowSoftInputMode="stateHidden|adjustPan" /> 

The code is in code

  String[] list = {"match1", "match2", "match3", "match12", "match11", "match8", "match7", "match4", "match13", "match10", "match9", "match6", "match5",}; AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.TestLayoutActivity_autoCompleteTextView); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.simple_list_item_1, list); autoCompleteTextView.setAdapter(adapter); Before 

Before

 After 

[ after]

0
source

All Articles