软键盘正常启动时无法调整布局

Cannot adjust layout when softkeyboard is up properly

我的 android 布局有问题。基本上我在清单中添加了以下行

    android:windowSoftInputMode="stateVisible|adjustResize"

这是我的布局:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFF"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <####.TitleBar
            android:id="@+id/title_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:barLeftButton="false"
            app:barRightButton="true"
            app:barTitle="?attr/titleBarContactUs"
            app:overrideBackground="#0C2938"
            app:overridePaddingLeft="10dp"
            app:overridePaddingRight="10dp"
            />

        <####..AdaptableFontTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:gravity="left"
            android:text="Come possiamo aiutarti?"
            android:textColor="#0C2938"
            android:textSize="26dp">

        </####..AdaptableFontTextView>

        <android.support.v4.widget.Space
            android:layout_width="match_parent"
            android:layout_height="10dp" />

        <####..AdaptableFontTextView
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="25dp"
            android:text="@string/contact_us_description"
            android:textAlignment="textStart"
            android:textColor="#0C2938"
            android:textSize="?attr/contactUsFontSize">

        </####..AdaptableFontTextView>

        <android.support.v4.widget.Space
            android:layout_width="match_parent"
            android:layout_height="20dp" />


        <Spinner
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:id="@+id/contact_us_spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:theme="@style/ThemeSpinner"
            android:minHeight="40dp"
            android:minWidth="300dp"/>

        <android.support.v4.widget.Space
            android:layout_width="match_parent"
            android:layout_height="10dp" />

        <EditText
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:id="@+id/contactUsUserText"
            android:layout_width="wrap_content"
            android:layout_height = "wrap_content"
            android:layout_weight = "1"
            android:layout_gravity="center_horizontal"
            android:background="@color/ksw_md_ripple_normal"
            android:gravity="left"
            android:hint="@string/begin_fragmetn_input_hint"
            android:inputType="textMultiLine"
            android:textAlignment="viewStart"
            android:textSize="?attr/highContrastBeginText"
            android:textCursorDrawable="@drawable/color_cursor"

            />

        <android.support.v4.widget.Space
            android:layout_width="match_parent"
            android:layout_height="20dp" />

        <Button
            android:id="@+id/ContactUsSendEmail"
            android:layout_weight = "0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|bottom"
            android:layout_marginBottom="5dp"
            android:background="@drawable/button_oval_black"
            android:text="Invia"
            android:textSize="?attr/highContrastBeginText"
            android:textColor="#FFF"
            />


    </LinearLayout>

这就是这个布局的代码(它是一个片段)

public class ContactUsModalFragment extends BaseFragment implements View.OnClickListener {

protected Button sendEmailButton;
protected EditText editText;
protected String choice;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.contact_us_fragment, container, false);
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    TitleBar titleBar = view.findViewById(R.id.title_bar);
    titleBar.setRightButtonOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            BaseModalDialogFragment.dismissModal(getContext());
        }
    });

    Spinner spinner = (Spinner) view.findViewById(R.id.contact_us_spinner);
    final ArrayList<String> choices = new ArrayList<>();
    choices.add("Sun");
    choices.add("Antares");
    choices.add("Alpha Centauri");
    choices.add("Tau Ceti");
    choices.add("Seleziona una categoria");

    /*ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(),R.layout.spinner_element_container,
            choices);*/


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),R.layout.spinner_element_container) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            if (position == getCount()) {
                ((TextView)v.findViewById(android.R.id.text1)).setText("");
                ((TextView)v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed"
            }

            return v;
        }

        @Override
        public int getCount() {
            return super.getCount()-1; // you dont display last item. It is used as hint.
        }

    };

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    adapter.addAll(choices);

    spinner.setAdapter(adapter);
    spinner.setSelection(adapter.getCount()); //display hint
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view,
                                   int position, long id) {
            Object item = adapterView.getItemAtPosition(position);
            if (item != null && position!=choices.size()-1) {
                choice = item.toString();
                }

            }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            // TODO Auto-generated method stub

        }
    });

    sendEmailButton = (Button) view.findViewById(R.id.ContactUsSendEmail);
    sendEmailButton.setOnClickListener(this);
    editText = (EditText) view.findViewById(R.id.contactUsUserText);

    return view;
}

基本上,当我使用带有大屏幕的设备时,编辑文本会上升并且第一行会显示,当我使用较小的设备时,布局会上升但不够,而且我的编辑文本会被键盘覆盖. 建议?

Edit Text covered by keyboard

Normal layout

在对应于 activity 的 android 清单文件中试试这个。

<activity android:windowSoftInputMode="adjustPan|adjustResize”> </activity>

** 您给定的布局代码的根是 LinearLayout。此布局找不到足够的 space 来调整您的视图和键盘。请将 ScrollView 作为 root 和 Scrollview 内部的其他布局元素。