android - ImageView AlignParentBottom

标签 android android-imageview android-relativelayout

在我的应用程序中,我有一个与按钮对齐的 ImageView,位于布局的 Root View RelativeLayout 中:

enter image description here

问题是键盘打开的时候一起上去:

enter image description here

我试图通过将它放在 list 中来修复它:`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>

最佳答案

而不是使用 android:windowSoftInputMode="stateVisible|adjustPan" 使用它来隐藏特定 View
RelativeLayout rootView = (RelativeLayout) findViewById(R.id.root)
rootView 只是一个指向你的 Root View 的 View ,在这种情况下是一个相对布局(给你的相对布局一个 id)

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);


                    }
                }
            });

感谢回答herehere

关于android - ImageView AlignParentBottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51180232/

相关文章:

java - Android 在其他 TextView 上方添加 TextView

java - 依赖注入(inject) : binding to specific value of a constructor parameter

android - 可点击的 ImageView 和 ImageButton 的区别

android - RecyclerView 和 Picasso 图像在滚动后消失

android - RelativeLayout 子级 onClick 传播

android - RelativeLayout 有效,而 ConstraintLayout 失败

java - Flutter for Mac 上的 Java 问题

java - 谁能解释一下这个简单游戏中红船背后的数学原理? [制导导弹式]

Android Studio 4.0 不高亮和着色原生 C++ 代码语法

android - TouchImageView 缩放缩放到 picasso 框架