I want the recyclerview to adjust it's height so that the items don't get hidden behind the pricebar ( see image )
This is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutMainContainer"
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"
tools:context="com.mridulahuja.groceryapp.activities.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:background="@null" />
<RelativeLayout
android:id="@+id/layoutPricebar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#454560"
android:layout_alignParentBottom="true"
android:visibility="gone">
...
...
</RelativeLayout>
</RelativeLayout>
Code I'm using to resize recyclerview:
ViewTreeObserver pricebarvto = layoutPricebar.getViewTreeObserver();
pricebarvto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
layoutPricebar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
layoutPricebar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
pricebarHeight = layoutPricebar.getMeasuredHeight();
}
});
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) recyclerView.getLayoutParams();
params.height = relativeLayoutContainerHeight - pricebarHeight;
recyclerView.setLayoutParams(params);
where relativeLayoutContainerHeight
is the height of the root RelativeLayout
But the height isn't changing. It's changing when I hard-code a big value
to pricebarHeight
such as 160. And I've given pricebar the height of just 50dp.
Also I'm using this animation to display the pricebar:
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromYDelta="180%"
android:toYDelta="0%">
</translate>