在我的应用程序中,我有一个ImageView,它与臀部对齐,位于RelativeLayout中,它是Layout的根视图:
问题在于,当键盘打开时,它会同时向上弹起:
我试图通过将其放入清单中来解决它:`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>
答案 0 :(得分:1)
代替使用android:windowSoftInputMode="stateVisible|adjustPan"
来隐藏特定视图
RelativeLayout rootView = (RelativeLayout) findViewById(R.id.root)
rootView只是指向您的根视图的视图,在这种情况下是相对布局(为您的相对布局提供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);
}
}
});