9

In meinem Fragmente Ich habe eine editText in einem Scrollview und wenn ich auf, dass ich es so öffnen gesetzt:Tastatur überlappende EditText auf Klick

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 

Es funktioniert vom ersten Mal öffnet, aber Wenn ich die Tastatur schließe und sie wieder öffne, überlappt sie den editText. Wie kann ich einstellen, dass der editText immer im SOFT_INPUT_ADJUST_PAN-Modus geöffnet wird?

die XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/alabaster"> 

    <TextView 
     android:id="@+id/semconexao" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Verifique sua conexão com a internet" 
     android:gravity="center" 
     android:layout_marginTop="10dp" 
     android:visibility="gone"/> 


    <ScrollView 
     android:id="@+id/scroll" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/footer"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:visibility="visible"> 



       <com.android.volley.toolbox.NetworkImageView 
        android:id="@+id/imageInst" 
        android:layout_width="match_parent" 
        android:layout_height="200dp" 
        android:scaleType="centerCrop" 
        android:visibility="visible" /> 

       <com.retornar.utils.CircledNetworkImageView 
        android:id="@+id/thumbnail" 
        android:layout_width="@dimen/logo_maior" 
        android:layout_height="@dimen/logo_maior" 
        android:layout_marginLeft="20dp" 
        android:layout_marginTop="100dp" 
        android:adjustViewBounds="true" 
        android:scaleType="centerCrop"> 

       </com.retornar.utils.CircledNetworkImageView> 

       <ImageView 
        android:id="@+id/more" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_amp" 
        android:visibility="gone" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentEnd="true" /> 

      </RelativeLayout> 


      <TextView 
       android:id="@+id/retornarTitulo" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/imageInst" 
       android:layout_marginTop="20dp" 
       android:gravity="center" 
       android:padding="10dp" 
       android:text="@string/retornarTitulo" 
       android:textColor="@color/armadillo" 
       android:textSize="@dimen/text2" /> 


      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/retornarTitulo" 
       android:gravity="center" 
       android:padding="10dp" 
       android:text="@string/retornar" 
       android:textColor="@color/armadillo" 
       android:textSize="@dimen/text1" /> 

      <include layout="@layout/valores" /> 


      <EditText 
       android:id="@+id/campovalor" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="60dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginTop="10dp" 
       android:background="@drawable/shadoweditext" 
       android:gravity="center" 
       android:hint="ou entre com um valor" 
       android:imeOptions="actionDone" 
       android:inputType="numberDecimal" 
       android:padding="10dp" 
       android:singleLine="true" /> 


      <View 
       android:layout_width="match_parent" 
       android:layout_height="1dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginTop="20dp" 
       android:background="@color/gray" /> 

      <TextView 
       android:id="@+id/propText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="30dp" 
       android:layout_marginTop="20dp" 
       android:gravity="center" 
       android:padding="10dp" 
       android:text="Propósito em destaque" 
       android:textColor="@color/armadillo" 
       android:textSize="@dimen/text2" 
       android:visibility="gone" /> 

      <include layout="@layout/inst_prop" /> 

      <ImageView 
       android:id="@+id/maisprop" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="20dp" 
       android:src="@drawable/ic_proposito" 
       android:visibility="gone" /> 

      <TextView 
       android:id="@+id/maisproptext" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="80dp" 
       android:layout_marginTop="10dp" 
       android:gravity="center" 
       android:text="Mais propósitos" 
       android:textColor="@color/armadillo" 
       android:visibility="gone" /> 

     </LinearLayout> 
    </ScrollView> 

    <TextView 
     android:id="@+id/ret" 
     fontPath="fonts/Avenir-Bold.ttf" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:alpha="0.9" 
     android:background="@color/blumine" 
     android:gravity="center" 
     android:padding="15dp" 
     android:text="DOAR" 
     android:textColor="@color/white" /> 

</RelativeLayout> 
+0

Ich glaube, Sie müssen hinzufügen Scroll als Mutter von layout.after kann dein Code funktionieren. [this] (http://stackoverflow.com/questions/8000795/android-keyboard-overlaps-with-the-edittext-with-printscreens) Link hilft Ihnen – pRaNaY

+0

Haben Sie versucht, es im Manifest festlegen? – zgc7009

+0

@ zgc7009 Wie kann ich das mit einem Fragment tun? – AND4011002849

Antwort

14

Was RESIZE statt PAN Einstellung? Sie können Ihre EditText über der halten. Versuchen Sie wie folgt vor:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 

Anstatt jedoch diese zur Laufzeit zu tun, können Sie es in der manifest als Activity(Eltern) festlegen Attribut.

<activity 
    android:name=".NameActivity" 
    android:label="@string/app_name" 
    android:windowSoftInputMode="stateAlwaysHidden|adjustResize"> 

Dann wird, wie Sie sehen können, die EditText über dem Softkeyboard, sondern von Ihrem Layout, haben Sie ein TextView mit android:layout_alignParentBottom="true" Attribute, das überlappt: Das wird auch in Ihrem Fragmente (Kind) behandelt werden die EditText:

1_screenshot_overlap_resize

dieses Verhalten zu vermeiden, sollten nur die ScrollView oberhalb des letzten TextView wie folgt:

<ScrollView 
    android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/ret"> <!-- instead of "footer" --> 

Und Sie werden folgendes Ergebnis:

2_screenshot_no_overlap_resize

+0

Das ist es, danke Kumpel! – AND4011002849

+1

@Filo warum funktioniert nicht der gleiche Code nicht in BottomSheetFragment durch Aufruf von * getDialog(). GetWindow(). SetSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); * in Oncreateview –

5

Versuchen Sie dieses, fügen Sie diesen Code in Ihre AndroidManifest.xml Aktivität

android:windowSoftInputMode="adjustPan" 
+0

Ich wünschte, alle Probleme könnten gelöst werden so leicht! Vielen Dank –

Verwandte Themen