2017-01-21 1 views
0

Keyboard pushes the view upКак предотвратить клавиатуру от нажатия некоторых элементов над клавиатурой в студии Android?

При активации клавиатуры три кнопки ОТКРЫТЬ, СОХРАНИТЬ, ОЧИСТИТЬ (показан на скриншоте выше) вверх. Есть ли способ предотвратить их рост?

Вот мои activity_main.xml коды:

<?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:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:fitsSystemWindows="true" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="p32929.cgpacalculator.Activities.MainActivity"> 

    <TextView 
     android:layout_width="match_parent" 

     android:layout_height="wrap_content" 
     android:text="@string/input" 
     android:textAlignment="center" 
     android:textSize="15sp" 
     android:textStyle="normal|bold" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100"> 

     <EditText 
      android:id="@+id/mainCredit" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:hint="Credit" 
      android:inputType="numberDecimal" 
      android:maxLines="1" 
      android:nextFocusDown="@+id/mainGpa" 
      android:textAlignment="center" 
      android:textColor="#000000" 
      android:textColorHint="@color/hint" /> 

     <EditText 
      android:id="@+id/mainGpa" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:hint="GPA" 
      android:imeOptions="actionDone" 
      android:inputType="numberDecimal" 
      android:textAlignment="center" 
      android:textColor="#000000" 
      android:textColorHint="@color/hint" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:paddingBottom="7dp" 
     android:weightSum="10"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="3" 
      android:gravity="center" 
      android:text="CGPA = " 
      android:textAlignment="center" 
      android:textColor="#000000" 
      android:textSize="24sp" /> 

     <TextView 
      android:id="@+id/mainCGPA" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:gravity="center" 
      android:text="0.00" 
      android:textAlignment="center" 
      android:textColor="#000000" 
      android:textSize="24sp" /> 

     <Button 
      android:id="@+id/MainAdd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:gravity="center" 
      android:onClick="Clicked" 
      android:text="Add" /> 

    </LinearLayout> 

    <TextView 
     android:id="@+id/infotext" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAlignment="center" 
     android:textColor="#5c5c5c" 
     android:textStyle="normal|bold" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="3dp" 
     android:layout_marginLeft="3dp" 
     android:layout_marginRight="3dp" 
     android:layout_marginTop="3dp" 
     android:weightSum="100"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="25" 
      android:text="Serial" 
      android:textAlignment="center" 
      android:textColor="@color/text" 
      android:textSize="14sp" 
      android:textStyle="normal|bold" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="5dp" 
      android:layout_weight="25" 
      android:text="Credit(s)" 
      android:textAlignment="center" 
      android:textColor="@color/text" 
      android:textStyle="normal|bold" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="13dp" 
      android:layout_weight="25" 
      android:text="GPA" 
      android:textAlignment="center" 
      android:textColor="@color/text" 
      android:textStyle="normal|bold" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="5dp" 
      android:layout_weight="25" 
      android:text="Total" 
      android:textAlignment="center" 
      android:textColor="@color/text" 
      android:textStyle="normal|bold" /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listview" 
     android:layout_width="match_parent" 
     android:layout_height="388dp" 
     android:layout_weight="3.58" 
     android:choiceMode="multipleChoice" 
     android:paddingTop="3dp"> 


    </ListView> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="9"> 

     <Button 
      android:id="@+id/openData" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:onClick="openData" 
      android:text="Open" /> 

     <Button 
      android:id="@+id/saveData" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:onClick="saveData" 
      android:text="Save" /> 

     <Button 
      android:id="@+id/clearData" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:onClick="clearData" 
      android:text="Clear" /> 

    </LinearLayout> 


</LinearLayout> 

Я пробовал все решения, приведенные здесь: Android: How do I prevent the soft keyboard from pushing my view up?

Но это все та же.

ответ

0

удалить андроида: fitsSystemWindows = «истина» из вашего XML или изменить его на «ложь»

+0

, из которого xml ?? – p32929

0

эти вопросы было предложено много, и есть много ответов, но ..

Там нет надежных API для обнаружения, когда отображается клавиатура. Вы увидите «решения» на этом сайте, но у них есть ложные срабатывания и негативы. Но для вас лучше всего установить softInputMode на номер adjustPan. Это заставит ОС прокрутить весь экран на минимальное количество, необходимое для того, чтобы курсор был виден над клавиатурой. (все приложение выходит за клавиатуру из-за режима adjustResize).

процитировать @Gabe Sechan из latest bounty question по соответствующему предмету


Но все-таки иногда я использую ниже метод в качестве альтернативы.

В вашем OnCreate инициализации rootView (родительское представление в вашем XML) и ваш footerView

вызывать этот метод из вашего OnCreate - когда клавиатура вверх вы можете изменить видимость представлений, которые вам не нужны, чтобы показать ! Когда клавиатура выключена, снова отобразите их.

public void testKeyBoardUp(){ 
     rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
      @Override 
      public void onGlobalLayout() { 
       Rect r = new Rect(); 
       rootView.getWindowVisibleDisplayFrame(r); 
       int heightDiff = rel.getRootView().getHeight() - (r.bottom - r.top); 

       if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard... 
        //ok now we know the keyboard is up... 
        whatEverView.setVisibility(View.INVISIBLE); 


       }else{ 
        //ok now we know the keyboard is down... 
        whatEverView.setVisibility(View.VISIBLE); 


       } 
      } 
     }); 
    } 
+0

@ p32929 Помог ли вам этот ответ? –

Смежные вопросы