Android androidx.recyclerview remove Scroll Effect - android-recyclerview

I've just migrated the code base to Androidx and found that all the recyclerViews have their Scroll Effect showing again.
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/mRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:descendantFocusability="blocksDescendants"
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
android:paddingTop="32dp"
android:paddingBottom="32dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="9"
tools:listitem="#layout/item_section_other" />
Before androidx I removed the scroll effect adding
android:overScrollMode="never"
but it seems that's not working anymore.
Any solution?
Thanks

Related

CollapsingToolbarLayout not Collapsing with RecyclerView Scroll Behavior

I have a CollapsingToolbarLayout that shows an image (placed inside the ConstraintLayout to keep the ratio 1:1) and a RecyclerView that has the com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior attached to it.
Image of Layout
The image is in green and the RecyclerView is in blue.
The problem is when I scroll up on the RecyclerView, the CollapsingToolbarLayout doesn't collapse. Instead, the RecyclerView just scrolls underneath the entire layout. I have to manually scroll inside the CollapsingToolbarLayout for it to collapse.
Here is the code for the layout:
<androidx.coordinatorlayout.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">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:src="#drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent"
android:nestedScrollingEnabled="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="#android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I originally had the RecyclerView inside a NestedScrollView with the scrolling behavior attached to the NestedScrollView, but this was causing issues with the Adapter creating a ViewHolder object for EVERY single item in the RecyclerView and that was causing a lot of performance and lagging/freezing issues.
From my understanding, a RecyclerView should not be placed inside a NestedScrollView for this reason and that is why I took the NestedScrollView out.
Any help would be appreciated!
Simply you should disable nested scrolling in recycler view
android:nestedScrollingEnabled="false"
Also, if you have nested recycler views you should disable nested scrolling in child recycler views.
If you want the image to collapse when recyclerview scrolls, use this scroll flags
app:layout_scrollFlags="scroll|snap|enterAlwaysCollapsed"
and use
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
in your recyclerview , and android:nestedScrollingEnabled attribute is not required for what you want to achieve.
have you looked into https://www.journaldev.com/13927/android-collapsingtoolbarlayout-example
Also see some of the things you are missing

How to get rid of borders of recyclerview

The below settings give the left or right border of the recyclerview a vertical line.
I also tried to remove all the layout parameter of the recyclerview, still it does not work.
I did try to hide all the viewholder and found that the line truly belongs to the recyclerview
I am wondering if this line is default, or added by my code and how to get rid of it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/list_background_color">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/fake_space"
android:layout_gravity="center"
android:layout_marginBottom="0dp"
android:layout_marginEnd="1dp"
android:layout_marginStart="1dp"
android:clipToPadding="false"
android:gravity="center"
android:horizontalSpacing="20dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"
android:visibility="visible" />
</RelativeLayout>
</RelativeLayout>
Have you tried removing the background from the relative layout. I think you'll find that's what's giving you your border.
There's nothing in your RecyclerView as shown that could do it, even if there is anything that could do it, and I don't think there is. I think you need an ItemDecoration to get borders into the RecyclerView itself, and you're not showing one of those.

Image not appear using splash screen react native

i want to put image in splash screen react native but it didnt work. im using this library https://github.com/crazycodeboy/react-native-splash-screen
i put some text in it and it works fine. but the image doesnt appear at all. i tried it in android studio it works fine but when react native rendering image not appear at all
Image : png 32 bit
Here is it the code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:background="#color/white"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/splash" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:text="Tes"
android:textColor="#4972D1"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:text="Tes"
android:textColor="#759fff"
android:textSize="24sp" />
</LinearLayout>
Here is it in android studio
Here is it when i launch the app
According to the official docs, you should add scaleType property to your ImageView.
android:scaleType="centerCrop"
If it doesn't works please add your manifest file for further help.
You also need to add in the image in Splash.xml and then re-build the project.
Also add the images in drawable folder.

Androidx scrolling view behavior not working

After switching to androidx the following code stopped working. The TextView below the Toolbar used to scroll with the content, but now it doesn't. I managed to make it work only when I set the same scrollFlags to Toolbar, but I would like to keep that in place. Is there a solution to this besides moving the Toolbar out of AppBarLayout and CoordinatorLayout?
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
app:title="Non-scrollable title"
android:layout_width="wrap_content"
android:layout_height="?android:attr/actionBarSize"/>
<TextView
app:layout_scrollFlags="scroll"
android:layout_margin="16dp"
android:textSize="20sp"
android:text="this should scroll with the content"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- some scrollable content here -->
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
replace attribute
old:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
new:
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
and add
implementation 'com.google.android.material:material:1.0.0'
In my case, the problem was in the margins of NestedScrollView. I removed margins from NestedScrollView and everything started work.

How to merge two views in Android

My requirement is to display a pie chart and a bar graph in a page in Android. To do so, I am generating two views using the following:-
ChartFactory.getBarChartView(getActivity(), buildBarDataset(titles, values), renderer, Type.DEFAULT)
ChartFactory.getPieChartView(getActivity(), categorySeries, defaultRenderer)
I am able to display them individually. But I need to display both the views in a single page with scrolling. How can I achieve this??
Just create a layout like:
<LinearLayout 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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/view1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/view2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Save the result of your calls ChartFactory.getBarChartView() and ChartFactory.getPieChartView() in 2 variables graph1 and graph2
Then in code add the 2 charts to the layout
LinearLayout view1 = (LinearLayout)findViewById(R.id.view1);
LinearLayout view2 = (LinearLayout)findViewById(R.id.view2);
view1.removeAllViews();
view1.addView(graph1);
view2.removeAllViews();
view2.addView(graph2);
In my solution both charts are shown on one page. If you want each chart to fill one screen maybe this can help:
scrollable linearlayout with weights bigger than screen in android