为什么键盘在ScrollView内部时在AutoCompleteTextView上重叠

Chu*_* Wu 6 android android-layout

我有一个简单的android布局和代码,但是AutoCompleteTextView当我点击它时键盘总是重叠.注意:ScrollView内部的AutoCompleteTextView.注意:平台是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);
    }
}
Run Code Online (Sandbox Code Playgroud)

和我的AndroidManifest.xml在这里:

<?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>
Run Code Online (Sandbox Code Playgroud)


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>
Run Code Online (Sandbox Code Playgroud)

看到 问题2

Chu*_* Wu 0

键盘行为是滚动视图以关闭文本区域的底部。

最后,我们必须使用android:gravity="bottom"属性来解决UI问题,但我们需要考虑UX,例如:提示。

所以,解决方案是听onClick(),对于键盘问题,我们必须使用动态方法来设置重力。