putting recycler view above bottom navigation - java

i have a bottom navigation in main activity and what I'm trying to do is to show recyclerview above bottom navigation but my problem is bottom navigation is overlapping recyclerview and my recyclerview is in map fragment so that is why I'm not able to put it above bottom navigation i tried using margin but its cuts the recyclerview
my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.google.android.gms.maps.MapView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="#+id/item_picker">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</RelativeLayout>

Try this
android:layout_above="#+id/navigationLayout"
<android.support.v7.widget.RecyclerView
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_above="#+id/navigationLayout"
android:id="#+id/item_picker"/>

You are trying to set RecyclerView at the bottom of parent that's why your UI is overlapping.
Try this,
android:layout_below="#+id/mapView"
android:layout_above="#+id/yourBottomNavigationView"
So that it will not overlap with each other.

Related

Transparent TextView on top of RecyclerView

I have this activity where I have a RecyclerView but above it I have a TextView, now when I scroll in the RecyclerView the RelativeLayout with the text stays at the top of the screen and doesn't scroll with it. Now my problem is that the RelativeLayout view is transparent so when I scroll in the RecyclerView the text in the RelativeLayout will lay on top of the list of text elements in the RecyclerView, in other words to simplify what I mean, I have "text on text" if that makes sense. How can I either have the RelativeLayout not be transparent so that the RecyclerView items scroll "behind" it and aren't visible "underneath" the TextView or how would I be able to make the whole layout scroll together with the RecyclerView?
(Even if I change the background color of the RelativeLayout the text in the RecyclerView will be visible through it)
Here is the XML for this activity:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".Activity"
android:background="#drawable/gradient_background">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="#color/colorPrimary">
<View
android:id="#+id/lineView"
android:layout_width="30dp"
android:layout_height="0.5dp"
android:background="#drawable/divider_line"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_toEndOf="#id/lineView"
android:layout_margin="8dp"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
app:layout_constraintTop_toBottomOf="#+id/relativeLayout"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Use NestedScrollView to make whole view scrollable
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
tools:context=".Activity"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/gradient_background">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<View
android:id="#+id/lineView"
android:layout_width="30dp"
android:layout_height="0.5dp"
android:background="#drawable/divider_line"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_toEndOf="#id/lineView"
android:layout_margin="8dp"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Can I have the RelativeLayout not be transparent so that the
RecyclerView items scroll "behind" it?
Just change the Constraint Layout to Linear Layout.
How would I be able to make the whole layout scroll together with the
RecyclerView?
Logic: For that you would have to include the Relative layout in the XML file where you are inflating the RecyclerView content. Now that would inflate the Relative Layout every time right.
So to overcome this problem, whatever you are passing in the RecyclerView constructor, take a flag/count, only inflate the Relative Layout when count is equal to zero/ set the flag and when the count is greater than 0 or if flag is set, then hide the Relative Layout.
That way you would have Relative Layout scroll with the RecyclerView content and inflated only once.

How can show bottom navigation view at a top of the app?

I want to show the bottom navigation view at the top of my app like facebook, i try this but its not showing anything.
Use TabLayout and you will have something like that.
Here below is a video which I think it will help you.
You need to use Fragments and TabLayout
https://codinginflow.com/tutorials/android/tab-layout-with-fragments
It does not matter where the bottom navigation view is placed, you can just place it at top of your layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bottom_navigation_colors"
app:itemTextColor="#color/black"
app:menu="#menu/bottom_navigation_menu"
app:labelVisibilityMode="labeled"/>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

ListView in Fragment not covering full Parent

I have a ListView in a Fragment which isn't covering the whole Parent when the List isn't fully populated.
The Problem is the scrolling behaviour of the ListView, I can only browse in the small piece of window the ListView is initially loaded in.
(4 Entries or more do occupy the entire Parent, with less entries the problem happens)
Fragment:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
/> </LinearLayout>
Main XML:
<android.support.design.widget.CoordinatorLayout
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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:itemBackground="#color/bgBottomNavigation"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/navigation" />
</android.support.design.widget.CoordinatorLayout>
The ListView gets populated via Volley + JSON with an Adapter for the ListView. Comment if you need the Code.
When I'm trying to put the ListViews height on "match_parent" the whole screen is occupied by the ListView, but it isn't scrollable anymore.
What can I do?
EDIT:
Coordinator Layout - This is the Code of the Frame Coordinator with the Bottom Navigation in it:
<android.support.design.widget.CoordinatorLayout 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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:itemBackground="#color/bgBottomNavigation"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/navigation" />
</android.support.design.widget.CoordinatorLayout>
You could set a minimum height attribute to your listView and adjust to what suits you.
Eg. to set it to 20dp, add android:minHeight="20dp" to your listView attributes.
Best solution would be to wrap all the contents of the CoordinatorLayout inside a layout you can control yourself, like a ConstraintLayout. In that case you would align the FrameLayout (and the fragments it handles) between your other components and everything would be scrollable and clickable. A mock of this solution would be:
<CoordinatorLayout>
<ConstraintLayout height="match_parent">
<BottomNavigation bottomToBottomOf="parent" />
<FrameLayout height="0dp"
topToTopOf="parent"
bottomToTopOf="bottomNavigation" />
</ConstraintLayout>
</CoordinatorLayout>

unable to scroll the screen which has grid view and listview below it

I have the following xml which has Gridview and framelayout below it.
My requirement is if I scroll the screen upwards whole screen should scroll, but for me Only listview scrolls
Below is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:focusableInTouchMode="true"
android:paddingBottom="#dimen/activity_vertical_margin">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/time_card_header"
android:id="#+id/scrollView">
<GridView
android:id="#+id/timecard_grid"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_margin="3dp"
android:fitsSystemWindows="true"
android:gravity="center_horizontal"
android:horizontalSpacing="1dp"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp" />
</ScrollView>
<FrameLayout
android:id="#+id/timecard_reports"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:layout_below="#+id/scrollView"/>
</RelativeLayout
Actually GridView and Listview have already scroll. No need to put the above widgets in scrollview. Firstly, remove the scrollview. I think you need the FrameLayout to be fixed at the bottom and show gridview above. For that first use FrameLayout in the linear layout with align_parentbottom true. after that please place the gridview above FrameLayout. That will fix the problem.
Just put linearlayout below scroll view and then gridview.
<scrollview>
<linearlayout >
<gridview />
</linearlayout >
</scrollview>
Sorry i am giving the ans from the mobile but the concept is same.
You can use RecyclerView with GridLayoutManager and set nestedScrollingEnabled of recyclerView to false.
and instead of ScrollView use NestedScrollView as parent of RecyclerView:
private void setUpRecyclerView(View view) {
recyclerView = view.findViewById(id.repliesList);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(),numberOfColumns));
}
and xml file:
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:focusableInTouchMode="true"
android:paddingBottom="#dimen/activity_vertical_margin">
<RecyclerView
android:id="#+id/timecard_grid"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_margin="3dp"
android:fitsSystemWindows="true"
android:gravity="center_horizontal"
android:horizontalSpacing="1dp"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp" />
<FrameLayout
android:id="#+id/timecard_reports"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:layout_below="#+id/scrollView"/>
</RelativeLayout
</android.support.v4.widget.NestedScrollView>

HorizontalScrollView swipe/fling guesture listener

I know this is a common question , but I am completely messed with those different examples and tutorials available on the web.
I have a horizontalScrollView where I add some view dynamically , and I want to set a guestureListener for swiping through the Views . Each view's with is equal to the width of the screen.
You can use the View Pager instead of the horizontalScrollView. http://developer.android.com/reference/android/support/v4/view/ViewPager.html
To keep the View pager at half the screen use something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.5">
<android.support.v4.view.ViewPager
android:id="#+id/pagerPromo"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicatorPromo"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical">
This View Pager has a circle indicator at the bottom but you can remove that if you like. Just play around with the weights and see what works best for you.

Categories