Reputation: 456
In my application I have an ImageView that gets with buttom alignment, in a RelativeLayout which is the root view of the Layout:
The problem is that when the keyboard is opened, it goes up together:
I tried to fix it by putting it in Manifest: `android:windowSoftInputMode="stateVisible|adjustPan",
It works, the problem is that the FloatingButton stops scrolling too, is there any way to make ImageView only "locked" down when the keyboard opens?
The xml looks like this:
<?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>
Upvotes: 1
Views: 51
Reputation: 427
Instead of using android:windowSoftInputMode="stateVisible|adjustPan"
use this to hide specific views RelativeLayout rootView = (RelativeLayout) findViewById(R.id.root)
rootView is just a view pointing to your root view in this case a relative layout(give an id to your Relative layout)
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);
}
}
});
Thanks to answers here and here
Upvotes: 1