Переместить плавающую кнопку действия над клавиатурой

У меня есть эта Плавающая кнопка действия (ссылка на GitHub), и когда я открываю (программную) клавиатуру, появляется Плавающая кнопка действия прячется за клавиатурой.

Есть ли способ, которым я могу поместить его над клавиатурой?

Редактировать:

tab_random.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:layout_width="match_parent"
        android:layout_height="156dp"
        android:background="@color/primary_color"
        />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/from"
        android:inputType="number"
        android:imeOptions="actionNext"
        android:layout_centerHorizontal="true"
        android:hint="From"
        android:paddingStart="5dp"
        android:textColor="#FFF"
        android:fontFamily="sans-serif-light"
        android:textSize="44sp"
        android:backgroundTint="@color/fab_ripple"
        android:layout_marginStart="10dp"
            />

    <EditText
        android:textSize="44sp"
        android:layout_marginStart="10dp"
        android:paddingStart="5dp"
        android:fontFamily="sans-serif-light"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/from"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="To"
        android:inputType="number"
        android:imeOptions="actionSend"
/>
</RelativeLayout>

activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="activity.MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/tool_bar" />

    <slidingModel.SlidingTabLayout
        android:layout_below="@+id/toolbar"
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="4dp"
        android:background="@color/primary_color"
        />

    <android.support.v4.view.ViewPager
        android:layout_below="@id/tabs"
        android:id="@+id/pager"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"

        />

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="16dp"
        fab:fab_colorNormal="@color/fab_normal"
        fab:fab_colorPressed="@color/fab_pressed"
        fab:fab_colorRipple="@color/fab_ripple"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

person Gursimran Bedi    schedule 26.08.2015    source источник
comment
Я думаю, что это ваша проблема макета.   -  person IntelliJ Amiya    schedule 26.08.2015
comment
Я опубликую свою активность_main   -  person Gursimran Bedi    schedule 26.08.2015
comment
Вы добавили ответ @Raj. Попробуйте его путь   -  person IntelliJ Amiya    schedule 26.08.2015
comment
@IntelliJAmiya Да, я сделал. Все, что он сделал, это открыл клавиатуру, когда я открыл приложение.   -  person Gursimran Bedi    schedule 26.08.2015


Ответы (7)


Ваш макет сейчас такой:

<Relative Layout>
    <View/>
    <EditText/>
    <other stuff.../>
</RelativeLayout>

Вам нужно добавить прокрутку внутри тегов RelativeLayout. Кроме того, прокрутки не любят иметь более одного прямого дочернего представления, поэтому вам понадобится Relativelayout внутри прокрутки. Итак, ваш макет будет выглядеть так:

<RelativeLayout> (this was already here)
    <ScrollView> (this is new)
        <RelativeLayout> (this is also new)
            <View, EditText, Etc. in here/> (this is what used to be inside that original relative layout.)
        </RelativeLayout> (closing up the new Relativelayout)
    </ScrollView> (closing the new Scrollview)
</RelativeLayout> (closing the original Relative Layout.)
person MrPlow    schedule 26.08.2015
comment
FAB все еще за клавиатурой :( - person Gursimran Bedi; 26.08.2015
comment
разместил мою activity_main, если это поможет - person Gursimran Bedi; 26.08.2015
comment
похоже, все, что вам нужно сделать, это применить это исправление к вашему макету activity_main вместо того, что было другим. Поместите прокрутку вокруг всей страницы, кроме самой внешней группы просмотра. - person MrPlow; 26.08.2015

У меня была похожая проблема, после предложения @MrPlow, но там, где он добавил Scrollview внутри исходного RelativeLayout, а затем добавил еще один RelativeLayout внутри ScrollView (чтобы сохранить структуру форматирования), я просто обернул весь макет в ScrollView, и он 'только что работал'. Финал для OP тогда будет:

<Scrollview>
    <RelativeLayout>
        <View/>
        <EditText/>
        <other stuff.../>
    </RelativeLayout>
</Scrollview>
person jack bochsler    schedule 27.03.2016

Решением может быть размещение всего макета внутри ScrollView.

person Kabir    schedule 26.08.2015
comment
Как я могу это сделать? Я выложу свой макет, и вы можете сказать мне, как это сделать. - person Gursimran Bedi; 26.08.2015

Попробуйте с этим:

activity_main.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="activity.MainActivity">

<include
    android:id="@+id/toolbar"
    layout="@layout/tool_bar" />

<slidingModel.SlidingTabLayout
    android:layout_below="@+id/toolbar"
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="4dp"
    android:background="@color/primary_color"
    />

<android.support.v4.view.ViewPager
    android:layout_below="@id/tabs"
    android:id="@+id/pager"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"

    />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|bottom"
        android:layout_margin="@dimen/fab_margin" />

</ScrollView>

All I have done is put the fab inside a ScrollView.

person A. Urmeneta    schedule 20.12.2015

Будет ли FAB перемещаться над клавиатурой или нет, зависит от файла манифеста и, в частности, от тега android:windowSoftInputMode.

Чтобы заставить его двигаться над программной клавиатурой, я использую этот код (файл манифеста):

<activity 
    android:name=".activities.YourActivity" 
    android:screenOrientation="portrait" 
    android:windowSoftInputMode="adjustPan" 
    android:theme="@style/AppTheme.NoActionBar" />

Чтобы он оставался за программной клавиатурой, используйте это:

<activity 
    android:name=".activities.YourActivity" 
    android:screenOrientation="portrait" 
    android:theme="@style/AppTheme.NoActionBar" />
person Andrew Primakov    schedule 24.09.2020

Сделай это

<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="match_parent">

<View
    android:layout_width="match_parent"
    android:layout_height="156dp"
    android:background="@color/primary_color"
    />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/from"
    android:inputType="number"
    android:imeOptions="actionNext"
    android:layout_centerHorizontal="true"
    android:hint="From"
    android:paddingStart="5dp"
    android:textColor="#FFF"
    android:fontFamily="sans-serif-light"
    android:textSize="44sp"
    android:backgroundTint="@color/fab_ripple"
    android:layout_marginStart="10dp"
        />

<EditText
    android:textSize="44sp"
    android:layout_marginStart="10dp"
    android:paddingStart="5dp"
    android:fontFamily="sans-serif-light"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/from"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="To"
    android:inputType="number"
    android:imeOptions="actionSend"
  />
  </ScrollView>
  </RelativeLayout>

Поскольку ваши элементы теперь находятся внутри прокрутки, они будут прокручиваться.

person rockfight    schedule 26.08.2015
comment
FAB все еще находится за клавиатурой, когда я ввожу этот код. - person Gursimran Bedi; 26.08.2015
comment
Опубликовал мой файл activity_main.xml - person Gursimran Bedi; 26.08.2015

ТРУ, ЧТОБЫ СДЕЛАТЬ ЭТО. ЭТО РАБОТАЛО ДЛЯ МЕНЯ.

добавьте stateVisible|adjustPan В ВАШУ ДЕЯТЕЛЬНОСТЬ В ВАШЕМ ФАЙЛЕ МАНИФЕСТА.

<activity 
android:name="com.comapny.applicationname.activityname"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustPan"/>
person RajSharma    schedule 26.08.2015
comment
Мне вообще не помогло :( - person Gursimran Bedi; 26.08.2015
comment
Вы хотите отобразить его поверх клавиатуры или немного сдвинуть вверх, чтобы его можно было увидеть? Если вы отобразите его поверх клавиатуры, клавиатуру нельзя будет нажать. - person RajSharma; 26.08.2015
comment
Я хочу отобразить его поверх клавиатуры, чтобы он был виден. - person Gursimran Bedi; 26.08.2015
comment
сделай это, если хочешь потрясающую кнопку за клавиатурой, спасибо - person vuhung3990; 25.10.2015