Android ImageView与底部对齐
在我的应用程序中,我有一个使用按钮对齐的ImageView,位于RelativeLayout中,它是布局的根视图: 问题是,当键盘打开时,它会同时上升: 我试图通过将其放入清单来修复它:`android:WindowsOfInputMode=“stateVisible | adjustPan” 它可以工作,问题是浮动按钮也停止滚动,有没有办法在键盘打开时使ImageView仅“锁定”下来 xml如下所示:Android ImageView与底部对齐,android,android-imageview,android-relativelayout,Android,Android Imageview,Android Relativelayout,在我的应用程序中,我有一个使用按钮对齐的ImageView,位于RelativeLayout中,它是布局的根视图: 问题是,当键盘打开时,它会同时上升: 我试图通过将其放入清单来修复它:`android:WindowsOfInputMode=“stateVisible | adjustPan” 它可以工作,问题是浮动按钮也停止滚动,有没有办法在键盘打开时使ImageView仅“锁定”下来 xml如下所示: <?xml version="1.0" encoding="utf-8"?>
<?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:WindowsOfInputMode=“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);
}
}
});