Can't scroll RecyclerView - android

I can't scroll my RecyclerView to the end. It cut off my last element and I completly don't know why. I have another RecyclerView in my project, which also seems to be broken.
Here is my layout code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container"
android:padding="10dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv"
app:cardCornerRadius="2dp"
app:cardUseCompatPadding="true">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="220dp"
android:orientation="horizontal">
(...)
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView17"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="HISTORIA"
android:id="#+id/textView17"
android:layout_below="#+id/cv"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Another broken RecyclerView:
<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"
tools:context="com.praca_inz.Fragments.PetrolFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:scaleType="center"
android:src="#drawable/ic_editor_mode_edit"
android:layout_marginBottom="70dp"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Any ideas, because I don't have any.

You've got an issue in your first layout. In a RelativeLayout, a match_parent sized element will have exactly the same size as the layout itself. That's the case of your RecyclerView. However, it's not at the top of the layout, as it's below the #+id/textView17 TextView. So you're missing roughly 250~300dp of your RecyclerView (card's + text's height). You should probably use a vertical LinearLayout in this case, that's exactly what they're made for. Just set the RecyclerView's height to 0 and weight to 1.

You should set padding bottom in your RecyclerView. Like this:
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView17"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingBottom="20dp" />
I hope help you, and sorry for my bad english.

There was a problem with ViewPager in MainActivity layout. The solution was to set a paddingTop parameter, to 105dp (to cover Toolbar and TabLayout) and delete app:layout_behavior="#string/appbar_scrolling_view_behavior" parameter.
Before:
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
After:
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="105dp"/>
Thank you #oguzhand, for directing me to solution!

Add alignParentBottom="true" to the recyclerView. That should pin it to the bottom edge and the top will be pinned to the textview via the layoutBelow tag you already have in place

Related

Two recycleviews in one activity scroll problem

I have created 2 recycleviews in one activity. One scrolls horizontally while other scrolls vertically. I can scroll correctly inside each RecyclerView but the page as a whole won't scroll i.e. top RecyclerView stays at the top always and bottom one stays at the bottom like both are fixed in position.
<ScrollView
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"
android:orientation="vertical"
tools:context="com.shakeelnawaz.recipes.AllRecipesFragmet">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/trending_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontaltrendingrecycleview"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginStart="15dp"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/all_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
I read this post "Scolling with multiple RecyclerViews in Layout" and set vertical recycleview's height programmatically. like this
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
// calculate height of RecyclerView based on child count
params.height=1150;
// set height of RecyclerView
recyclerView.setLayoutParams(params);
But the problem is that how I can calculate the height of RecyclerView based on child count?
Use NestedScrollView instead of ScrollView
and use this below line in your Fragment in Activity.
ViewCompat.setNestedScrollingEnabled(mYourRecycleView, false);
This will be work on all your Android API level.
Replace ScrollView with NestedScrollView
Then add: horizontaltrendingrecycleview.isNestedScrollingEnabled = false
Your XML should look like below:
<android.support.v4.widget.NestedScrollView
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"
android:fillViewport="true"
tools:context="com.shakeelnawaz.recipes.AllRecipesFragmet">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="#string/trending_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/horizontaltrendingrecycleview"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_marginStart="15dp"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/all_recipes"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Recyclerview with fixed height wont scroll inside nested scroll view

I have a RecyclerView with a fixed height inside a NestedScrollView with a few other layouts inside it. The recycler view won't scroll, but it scrolls fine if I set its height to wrap_content.
I cannot make the RecyclerView use wrap_content because there is an issue with EndlessRecyclerViewScrollListener that it keeps loading data from the server and pushing it into my Adapter even if the user has not scrolled down at all.
Most are suggesting to set nested scrolling to false, but if I disable nested scrolling, the NestedScrollView does not allow me to scroll my RecyclerView. But if I leave nested scrolling enabled, the scroll view does not scroll unless I start touching from outside the RecyclerView.
My layout code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:background="#color/scoop_background"
tools:context=".module.scoop.timeline.ScoopTimelineFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="92dp">
<ImageView
android:id="#+id/ivTimelineBanner"
android:layout_width="match_parent"
android:layout_height="92dp"
android:layout_margin="0dp"
android:clickable="true"
android:padding="0dp"
android:scaleType="fitXY"
android:src="#drawable/banner_placeholder" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="92dp">
<TextView
android:id="#+id/tvGroupMembership"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="#dimen/text_content" />
<TextView
android:id="#+id/tvGroupName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="#dimen/text_header"
android:textStyle="bold" />
<TextView
android:id="#+id/tvGroupMemberCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="#dimen/text_content" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#null"
android:paddingStart="#dimen/divider_normal"
android:paddingEnd="#dimen/divider_normal"
android:src="#drawable/ic_chevron_right_white_24dp" />
</LinearLayout>
</FrameLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLayoutTimeline"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="4dp">
<android.support.v7.widget.CardView
android:id="#+id/cvCreateScoop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/divider_small"
android:layout_marginRight="#dimen/divider_small"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="#dimen/divider_normal">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:src="#drawable/svg_nav_create_scoop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingStart="#dimen/divider_normal"
android:text="What's on your mind?"
android:textSize="#dimen/text_content" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:padding="#dimen/divider_xsmall"
android:src="#drawable/svg_insert_image" />
</LinearLayout>
</android.support.v7.widget.CardView>
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
android:nestedScrollingEnabled="false"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingBottom="4dp">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
What do I have to modify so that the RecyclerView is scrollable, but the whole NestedScrollView also scrolls along with it, so that if the user is scrolling back up (swiping from top to bottom), the RecyclerView will scroll along with the NestedScrollView, which will bring the layouts above RecyclerView.
To visualize:
The layout I'm trying to achieve is similar to that of facebook's. When you scroll down, the timeline will scroll down, and the search bar with the messenger icon at the top is also scrolled so that it is hidden when scrolling down. When you scroll up, the timeline is being scrolled back up, and showing the search bar again.
I decided to do it differently because I wasn't able to solve it with this method. Instead, I used a CollapsingToolbar and put the other layouts inside it, then removing its background so it does not look like a toolbar, and it seamlessly does what I wanted to, just with a different implementation.

RecyclerView inside RecyclerView does not scroll

Hi I have a RecyclerView which contains another RecyclerView (please see the image), the inner RecyclerView does not scroll: for example look at the 7th of September in which the last activity is not visible at all but the RecyclerView does not scroll to display it.
Here's the outer layout:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/square">
<android.support.v7.widget.RecyclerView
android:id="#+id/reciclo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
and the inner one:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="20dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:id="#+id/square3"
android:src="#drawable/square"
android:elevation="2dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:minWidth="60dp"
android:layout_height="wrap_content"
android:id="#+id/lin"
android:orientation="vertical"
android:layout_marginLeft="30dp"
android:layout_marginRight="5dp"
android:layout_marginTop="30dp">
<TextView
android:id="#+id/day"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:id="#+id/nameeOfMonthTable"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recicloEvent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginRight="26dp"
android:layout_marginTop="20dp"
android:layout_toRightOf="#+id/lin"
android:paddingLeft="1dp"
android:layout_alignTop="#+id/square3"
android:layout_alignBottom="#+id/square3"/>
<View
android:id="#+id/separatorDateRvCale2"
android:layout_width="1dp"
android:layout_alignTop="#+id/square3"
android:layout_marginTop="21dp"
android:layout_height="200dp"
android:layout_alignBottom="#+id/square3"
android:layout_alignLeft="#+id/recicloEvent"
android:layout_marginLeft="60dp"
/>
<View
android:id="#+id/separatorDateRvCale"
android:layout_width="1dp"
android:layout_alignTop="#+id/square3"
android:layout_marginTop="21dp"
android:layout_height="200dp"
android:layout_alignBottom="#+id/square3"
android:layout_alignLeft="#+id/recicloEvent"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
any suggestions?
I believe here you can find an answer: How to add a recyclerView inside another recyclerView
All in all, you should not nest one RecyclerView inside another one.
You can also follow this guidance for further help.
I can see from your posted code that the height of the inner RecyclerView is wrap_content. I can only guess, but I suspect that each item of the outer RecyclerView has some fixed height. This will cause the inner RecyclerView to be clipped and not scroll.
You're going to want to make your inner RecyclerView have the same height as the item it is inside of. If you're using ConstraintLayout, that would mean using 0dp height and constraining the top and bottom to the parent. If you're using some other view, that would mean setting the height to match_parent.

Recyclerview within a Scrollview dont coordinate

I have this activity design, which shows a card view inside a scrollView, But under that cardview I need to put a listview or recyclerview. The problem is that I need the scroll of that list to coordinate with the main scroll. Osea that when lower in the content the cardview will disappear and the list of the recyclerview or listview will be crossed.
I need all the content to respond to the main scroll to show up and disappear after titlebar, Which should I change or redesign?
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
app:cardElevation="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/post_coordinator"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/post_bg"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="#drawable/default_profile" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:src="#drawable/ic_hot_black"
app:layout_anchorGravity="bottom"
android:layout_marginLeft="16dp"
app:layout_anchor="#id/post_bg"
android:tint="#FFF"
/>
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_anchor="#id/post_bg"
app:layout_anchorGravity="center_horizontal|bottom"
android:src="#drawable/profile"
app:civ_border_color="#FFF"
app:civ_border_width="3dp"
/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:src="#drawable/ic_hot_black"
app:layout_anchorGravity="bottom|end"
android:layout_marginRight="16dp"
app:layout_anchor="#id/post_bg"
android:tint="#FFF"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginTop="205dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="50dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepare your Anus Cersei Lanister, You Gonna Die"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"
android:textColor="#2d2d2d"
android:textAlignment="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="#string/emilia"
android:textColor="#color/secondary_text"
android:layout_marginTop="10dp"
/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v7.widget.CardView>
<ListView
android:id="#+id/post_comments"
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
</ScrollView>
Add your recyclerview inside NestedScrollview.
Also add recyclerview.setNestedScrollingEnabled(false);
Use android:fillViewport="true" to your ScrollView. ListView that located inside ScrollView works properly.
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
I'd recommend putting the CardView inside the RecyclerView as a header, and then you don't need the top ScrollView, the card and the list items would all be scrollable within the RecyclerView.
There are many ways to add a header to a RecyclerView, see here:
Is there an addHeaderView equivalent for RecyclerView?

Android - Padding/Gap on the left of toolbar's child layout

I'm stuck with an issue and I have browsed the entire internet for a solution but nothing is working for me.
I have added an imageview inside my toolbar but it's slightly towards the right. It doesn't align centrally, it's shifted a bit towards the right. When i align the imageview to the left, there's an unknown padding/gap between the imageview and the left side of the toolbar. Following is my XML code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".NavigationDrawerHomeScreen.BaseActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_home_activity"
android:layout_width="match_parent"
android:layout_height="45dp"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
android:contentInsetStartWithNavigation="0dp"
android:minHeight="?attr/actionBarSize"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/logo_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/fixer_title_thick" />
</RelativeLayout>
<android.support.v7.widget.SearchView
android:id="#+id/search_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:showAsAction="ifRoom"
android:visibility="gone">
</android.support.v7.widget.SearchView>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/container_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/home_bg" />
</FrameLayout>
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_centerInParent="true"-->
<!--android:text="this is base" />-->
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#2A2929"
android:backgroundTint="#2A2929"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_home_customer"
app:itemTextAppearance="#style/NavDrawerTextStyle"
app:itemTextColor="#fff"
app:menu="#menu/activity_home_customer_drawer">
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:clickable="true"
android:orientation="vertical">
<!-- any addition stuff you want in yoour footer layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Search Radius"
android:textColor="#color/white" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clipChildren="false">
<com.crystal.crystalrangeseekbar.widgets.CrystalSeekbar
android:id="#+id/rangeSeekbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bar_color="#color/blue"
app:left_thumb_color="#color/blue_dark" />
<TextView
android:id="#+id/textMin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rangeSeekbar1"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="0"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/textMax1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/rangeSeekbar1"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:text="100"
android:textColor="#color/white"
android:textSize="16dp" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#1E88E5">
<TextView
android:id="#+id/logout_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:drawableLeft="#drawable/ic_logout_white_24dp"
android:drawablePadding="32dp"
android:text="Logout"
android:textColor="#fff"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
</android.support.design.widget.NavigationView>
The app:contentinset/android:contentinset solution works for some people but it doesnt work for me.
here's the image http://imgur.com/a/Vp2g6.
I had this same problem, and I tried a lot of things like setting
app:contentInsetStart ="0dp" ;
app:contentInsetStartWithNavigation = "0dp" ;
It didn't work. I even set them to a negative value, but it didn't work. I tried adding a right margin to my child view but it reduced the visible size of child view instead of occupying that left space. So probably child views are not allowed in this space.
So after spending some time I figured there are 2 ways to workaround this problem, one is preferred other I'd not prefer. First let me tell you the one I do not prefer:
Custom Implementation of the Up button: This problem only arises when in your Java Class for this layout you set this toolbar as your ActionBar and you
setDisplayHomeAsUpEnabled(true);
Without this command this problem doesn't exist. So if you don't use the default back button and implement one your own by putting an imageView and providing onClick implementation, this should work fine.
Make ChildViews as rather Siblings: The other method is using the property of toolbar of it being just another view.
I prefer this method because by using this method you can use the android's default up button. The only thing you need to do is - instead of defining child views inside the toolbar, make the child view and toolbar as siblings in a Linear or Relative Layout. This way you can reduce the left space only to "wrap_content" of the toolbar and utilise the left space in other child views. In my app, I even had an onClick functionality on the toolbar which can now be done by giving that functionality on the parent of both the layouts i.e. set the onClick on the LinearLayout.
Though I still don't know the exact reason why the left space exists or is there a way to disable it, but this is a pretty clean method to work around this.

Categories

Resources