Make over scroll glow be outside the padding - android

I have the following:
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
I add this for a cleaner UI:
android:paddingEnd="16dp"
android:paddingStart="16dp"
However, now the scroll bar is inside the padding and looks funky. So I add:
android:scrollbarStyle="outsideInset"
The scroll bar is now outside the padding, however, the over scroll glow is still inside the padding.
How do I get the over scroll glow to stretch across the padding?
EDIT:
Here's the full layout code that encounters the same issue as above.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView 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/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>

What you need to do is to apply android:clipToPadding="false" to RecyclerView. Consider this xml:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:paddingBottom="40dp"
android:clipToPadding="false"/>
Here's the result:

Your best bet would be to put padding inside RecyclerView's item layout and not on RecyclerView itself.
However, you could just use margins and the glow should stay inside the RecyclerView.

While the answer given by #azizbekian works, it's also possible to set clipToPadding programmatically.
In Kotlin: recyclerView.clipToPadding = false
In java: recyclerView.setClipToPadding(false)
My personal favorit is to extend RecyclerView and set a LayoutManager, clipToPadding and such in the init function (constructor).

Related

RecyclerView (wrap_content) inside of a BottomSheetDialogFragment

I'm facing a tricky situation here and I don't know how to solve this problem.
In my project I have a custom BottomSheetDialogFragment and in the layout a FrameLayout to add or replace Fragments.
Now I have a Fragment and inside I have a RecyclerView with the height:="wrap_content" because I want the BottomSheetDialogFragment only use the necessary space. Everything looks great, the problem appear when I put another view inside of the same layout and set the RecyclerView bellow or above of that view.
The RecyclerView ignores the size of the other view (or views) and always grows to the max screen size, and then it's no possible to see a few elements and even scroll.
I saw a solution, some developers are suggesting to add paddingBottom equals to the height of the view. But in my case doesn't works because I want to have a dynamic solution.
Above I'll share a few images of the problem and GitHub Repository with a sample.
Thanks for your attention!
I've manage to do what you need just need to use this as your fragment_sample.xml:
<LinearLayout 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="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rclItems"
android:text="#string/add_1_item"/>
</LinearLayout>
Explanation
Using a LinearLayout gives you the ability to work with weight, and the vertical orientation allows you to place an item below the other. The weight on the recyclerview will increase the height of it as needed until filling the screen. The next item you add would be added to the recyclerview but you'll need to scroll the list to see it
The android developers blog says that :-
The scrolling containers in your bottom sheet must support nested scrolling .
Try changing your fragment_sample.xml as below to make the recyclerview scroll working and to make the add button persistent.
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:id="#+id/next"
android:layout_above="#id/btnAddMoreItems"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.NestedScrollView>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:text="#string/add_1_item"/>
</RelativeLayout>
Note: making bottomsheet layout a child view of CoordinatorLayout will allow you to get the implement BottomSheetBehavior and recieve its transitions callbacks .

recyclerview items outside view bound invisible

I have the following situation: I have a vertical RecyclerView with padding and the parent layouts clipChildren and clipToPadding set to false like so:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:clipChildren="false"
android:clipToPadding="false">
<android.support.v7.widget.RecyclerView
android:layout_margin="#dimen/padding_medium"
android:id="#+id/recyclerview_pager"
android:layout_width="match_parent"
android:layout_height="#dimen/holder_height_medium"/>
</LinearLayout>
Moreover, I attach a rather unspectacular LinearLayoutManager like so:
MyLayoutManager layoutManager
= new MyLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerViewPager.setLayoutManager(layoutManager);
The view holder in the adapter is very simple too:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="#dimen/layout_padding_small"
android:paddingRight="#dimen/layout_padding_small"
android:paddingLeft="#dimen/layout_padding_small">
.....
</LinearLayout>
Now I get the following behavior: When I am scrolled to one view, the item that is supposed to be visible in the padding area outside the recycler view is not yet rendered. Only when I start scrolling slightly, the item appears is rendered and displayed in the padding area as desired:
How can I tell the recyclerview to layout the neighboring items before they are actually about to come into view? Using an item prefetch configuration on the LayoutManager did not help. I have searched the methods of the LayoutManager and did not find a good method to override exteding the.
Thanks in advance for any help, let me know if anything is still unclear.
You need to set clipToPadding=false to RecyclerView not to parent LinearLayout and also you can remove clipChildren
like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_margin="#dimen/padding_medium"
android:id="#+id/recyclerview_pager"
android:layout_width="match_parent"
android:clipToPadding="false"
android:paddingEnd="40dp"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingStart="40dp"
android:layout_height="#dimen/holder_height_medium"/>
</LinearLayout>
UPDATE
I've added padding to recyclerview to make visible next item of position.

RecyclerView item fills the whole screen

I have a Recyclerview which is working fine with the Android version 23 but if i am running the same code with the Android version 25 then the whole screen is occupied by the single item.
Initially the list looks fine where the item height is wrap content. But as i scroll the whole screen is occupied by single item.
Below is my layout containing RecyclerView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:scrollbars="vertical" />
</LinearLayout>
Your Recyclerview code is ok.
if you are using TextView or else in your iteam_raw.xml then make sure you give
"wrap_content"
iteam_raw.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Please use recyclerview item's main layout height "wrap_content".
Make sure that the all UI element you are using in ViewHolder must have height to wrap content and if you are using cardview as parent container make that height also wrap_content.
change the layout_height property from match_parent to wrap_content or some size in your linearlayout.
example:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="120dp" <-- **change in height**
android:layout_width="match_parent"
android:orientation="vertical">
Set layout height and width to 0dp
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_height="0dp"
android:layout_width="0dp"
android:scrollbars="vertical" />

Horizontal RecyclerView inside vertical ScrollView

So I have a horizontal RecyclerView inside a vertical ScrollView. Everything inside my layout is displayed fine and it all scrolls in the directions I want and it does it smoothly.
The only problem I have, is that the RecyclerView is below some other content in the ScrollView and when the RecyclerView is partially visible, it will line the bottom of the RecyclerView with the bottom of the screen on start-up. This means that the content above the RecyclerView is pushed off the screen.
Does anyone know why this happens, and how I can fix it?
Here is a simple layout that does what I just described. You don't even need to populate the RecyclerView, it will still do it.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#fff"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#000"/>
</LinearLayout>
</ScrollView>
Turns out this issue was reported to Google here Issue - 81854
According to Google it is working as intended. The problem is the fact that RecyclerView has focusableInTouchMode set to true. To fix the problem I set focusableInTouchMode and focusable to true on the top-most view of the ScrollView.
Below is the fix for the code sample I provided in the original question:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#fff"
android:focusableInTouchMode="true"
android:focusable="true"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#000"/>
</LinearLayout>
</ScrollView>
I have been looking for a solution for a long time. In the end, I decided by accident. In your activity, find the ScrollView and add a touch listener for it. Everything will work as it should
ScrollView scroll = findViewById(R.id.scroll);
scroll.setOnTouchListener((view, motionEvent) -> {
return false;
});

Overlay for RelativeLayout inside ListView with match_parent

I am dealing with a weird problem.
I am using the following layout for ListView rows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:jn="http://schemas.android.com/apk/res/com.appeaser.justnoteproject"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<BUNCH OF VIEWS />
<RelativeLayout
android:id="#+id/rlCon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="#dimen/margin_note_bottom"
android:layout_marginLeft="#dimen/margin_note_left"
android:layout_marginRight="#dimen/margin_note_right"
android:layout_marginTop="#dimen/margin_note_bottom" >
<BUNCH OF VIEWS />
<View
android:id="#+id/vOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/blue_overlay"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
In my list adapter, I toggle vOverlay's visibility based on a certain condition. But, even after toggling the visibility, vOverlay is not displayed.
To verify that the code works as intended, I changed the height and width of vOverlay to 50dp. When I did this, vOverlay's visibility worked as intended - except that the size I need is match_parent.
Could someone explain what I'm doing wrong? How can I get intended results?
replace outer RelativeLayout with FrameLayout and move your overlay to be a second child of that FrameLayout

Categories

Resources