在我的应用程序中,我有一个与按钮对齐的 ImageView,位于布局的 Root View RelativeLayout 中:
问题是键盘打开的时候一起上去:
我试图通过将它放在 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);
}
}
});
关于android - ImageView AlignParentBottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51180232/