ImageView AlignParentBottom - PullRequest
       46

ImageView AlignParentBottom

0 голосов
/ 04 июля 2018

В моем приложении у меня есть ImageView, который получает с выравниванием по нижнему краю, в RelativeLayout, который является корневым представлением макета:

enter image description here

Проблема в том, что когда клавиатура открыта, она поднимается вместе:

enter image description here

Я попытался исправить это, поместив его в Manifest: `android: windowSoftInputMode =" stateVisible | AdjustPan ",

Работает, проблема в том, что FloatingButton тоже перестает прокручивать, есть ли способ сделать ImageView только "заблокированным" при открытии клавиатуры?

XML выглядит так:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:layout_alignParentBottom="true"
        app:srcCompat="@drawable/ic_rodape"/>

     <ScrollView........../>

     <android.support.design.widget.FloatingActionButton
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_margin="8dp"
        app:backgroundTint="@color/colorPrimary"
        app:srcCompat="@drawable/back"/>

</RelativeLayout>

1 Ответ

0 голосов
/ 04 июля 2018

Вместо использования android:windowSoftInputMode="stateVisible|adjustPan" используйте это, чтобы скрыть определенные виды
RelativeLayout rootView = (RelativeLayout) findViewById(R.id.root)
rootView - это просто представление, указывающее на ваше корневое представление, в данном случае относительное расположение (укажите идентификатор для вашего Относительного расположения)

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

                    if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                    //when the keyboard is up...
                        view_one.setVisibility(View.GONE);


                    }else{
                    //when the keyboard is down...
                        view_one.setVisibility(View.VISIBLE);


                    }
                }
            });

Благодаря ответам здесь и здесь

...