Problem with scrolling in Recyclerview. Scroll is not smooth - java

This is my code-
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/frame1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Recruitment Responses"
android:gravity="center"
android:textSize="30sp"
android:textColor="#fff"
android:background="#drawable/bg_rounded1"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/frame1"
android:background="#f9fafc"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
The scrolling is not smooth and is quite irritating can something be done to improve this? I want the textview to go up when scrolled upwards along with the Recycler View that is why i have nested both of them in a ScrollView and maybe that is what is creating an issue!

Adding a <androidx.core.widget.NestedScrollView> instead of ScrollView solves everything.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/frame1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Recruitment Responses"
android:gravity="center"
android:textSize="30sp"
android:textColor="#fff"
android:background="#drawable/bg_rounded1"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/frame1"
android:background="#f9fafc"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>

try this inside your activity:
recyclerView.setNestedScrollingEnabled(false);

Try this :
recyclerView.setScrollView(true);
This help you to make recyclerView scrollview smooth.

Related

Hide SearchView in Fragment

I want to hide my Searchview when I scroll in my Fragment. I use a RecyclerView to retrieve my item and scroll them.
My fragment are actually like that:
When I scroll I want it to hide and then when I return to the top, I want it to show.
This is the xml of my Fragment:
<?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:orientation="vertical"
tools:context=".stock.StockFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.SearchView
android:id="#+id/search_view"
android:layout_width="341dp"
android:layout_height="34dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/search_layout"
android:gravity="center"
app:iconifiedByDefault="false"
app:queryHint="Cerca Articolo">
</androidx.appcompat.widget.SearchView>
</LinearLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycleViewStock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
I tried to put it inside the Recycler but doesn't work, help please!
you can use NestedScrollView for scrolling all items.
<?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:orientation="vertical"
tools:context=".stock.StockFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<androidx.appcompat.widget.SearchView
android:id="#+id/search_view"
android:layout_width="341dp"
android:layout_height="34dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/search_layout"
android:gravity="center"
app:iconifiedByDefault="false"
app:queryHint="Cerca Articolo">
</androidx.appcompat.widget.SearchView>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycleViewStock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
After that set recyclerView.setNestedScrollingEnabled(false); in java for proper scrolling.

Swipe Refresh Layout and a WebView in a ScrollView

I have a header text and a webView in a LinearLayout in a ScrollView. I want to add a Swipe Refresh Layout, but I don't know where should I place it because I always get errors or the page is not displayed.
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
style="#style/PageTitle"
android:text="#string/news_in_fazekas" />
<WebView
android:id="#+id/newsWebView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
Try this way I hope it will work for you.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
style="#style/PageTitle"
android:text="#string/news_in_fazekasx" />
<WebView
android:id="#+id/newsWebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

Textview not showing inside FrameLayout

I have a linearlayout and a textview inside another linearlayout. The linearlayout from inside is displayed, but the problem is that the last textview is not. Why?
I have a LinearLayout and inside a FrameLayout and inside a SwipeRefreshLayout and in the middle a TextVeiw, but the problem is that TextView doesn't shows when I emulate the in the app. Why is that?
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SearchResults">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/content">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:text="EXAMPLE TEXT" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
Picture below...
Change your xml file with this code
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SearchResults">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:text="EXAMPLE TEXT" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</LinearLayout>
Your frame Layout height is 0
set to match_parent
LinearLayout (main)
SwipeRefresh...
RelativeLayout (gravity center)
and then your Textview
The framelayout height is set to 0dp, kindly change that to match parent.
try this:
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="EXAMPLE TEXT" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
it helps you
#George Patsias Change text color in textview

Using a Float Action Button Crossing Over Content and make it Scrollable

I have this code and I want to make it Scrollable, all it's content, what's the best way to make it? I tried just making ScrollView parent of all code but it just doesn't work, it only makes all white and not scrollable.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/viewOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="#android:color/holo_blue_light"
android:orientation="horizontal"/>
<LinearLayout
android:id="#+id/viewTwo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="#android:color/holo_orange_light"
android:orientation="horizontal"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_done"
app:layout_anchor="#id/viewOne"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="#FF0000"
app:rippleColor="#FFF" />
</android.support.design.widget.CoordinatorLayout>
Thanks in Advance guys

Layout not move up or panned when soft keyboard is shown in android java

I want to resize or pan layout when keyboard is displayed.
Here's my source code.
activity_forget_password.xml
<?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:fitsSystemWindows="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/forgot_password_bg"
android:scaleType="fitXY"
android:largeHeap="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp">
<com.opkix.app.utils.OpenSassTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/forget_password_introduce_string"
android:layout_alignParentBottom="true"
android:textColor="#android:color/white"
android:textSize="12sp"/>
</RelativeLayout>
</RelativeLayout>
manifest.xml
<activity android:name=".activities.auth.ForgetPasswordActivity"
android:windowSoftInputMode="adjustPan"
android:noHistory="true">
As you can see from my source code I added fitsSystemWindows and windowSoftInputMode.
Can anyone please help me?
add ScrollView as parent of RelativeLayout.It is not proper answer but it will work.
example
<?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:fitsSystemWindows="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/forgot_password_bg"
android:scaleType="fitXY"
android:largeHeap="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp">
<com.opkix.app.utils.OpenSassTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/forget_password_introduce_string"
android:layout_alignParentBottom="true"
android:textColor="#android:color/white"
android:textSize="12sp"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

Categories

Resources