为什么键盘重叠/推动编辑文本?

时间:2015-12-02 16:29:59

标签: android android-fragments

当运行我的应用程序并单击edittext来编写内容时,键盘会推动/重叠编辑文本,为什么?

This is before the overlap

This is after the overlap

这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:id="@+id/title"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:text="HJÆLP......"
    android:textSize="30dp"
    android:background="#00796b"
    android:textStyle="bold"
    android:textColor="#ffffff" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/suggestion"
    android:hint="Hvad er dit forslag?"
    android:gravity="top"
    android:layout_below="@+id/title"
    android:layout_alignParentStart="true"
    android:layout_marginTop="61dp"
    android:layout_alignParentEnd="true"
    android:editable="true"
    android:textAlignment="textStart"
    android:layout_above="@+id/suggestknap" />


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Send forslag"
    android:id="@+id/suggestknap"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="157dp"
    android:textColor="#ffffff"
    android:background="#00796b" />

这是片段的java类:

public class SuggestFrag extends Fragment implements View.OnClickListener {
Button suggestButton;
TextView title;
EditText suggestion;
Annonce annonce;

@Override
public View onCreateView(LayoutInflater i, ViewGroup container, Bundle savedInstanceState) {
    View rod = i.inflate(R.layout.frag_suggest, container, false);

    suggestButton = (Button)rod.findViewById(R.id.suggestknap);
    suggestButton.setOnClickListener(this);

    title = (TextView)rod.findViewById(R.id.title);

    suggestion = (EditText)rod.findViewById(R.id.suggestion);

    annonce = ((AnnonceDisplay)this.getActivity()).getAnnonce();

    title.setText(annonce.getItemname());

    return rod;
}

@Override
public void onClick(View view) {
    if(view == suggestButton) {
        AlertDialog alert = new AlertDialog.Builder(getActivity())
                .setMessage(suggestion.getText().toString())
                .setNeutralButton("ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }
                ).show();
    }
 }
}

1 个答案:

答案 0 :(得分:0)

您可以在android清单文件中将活动的windowSoftInputMode标志设置为adjustPan以防止此情况发生。

<activity
   ...
   android:windowSoftInputMode="adjustPan"> 
</activity>