RecyclerView inside ScrollView, some items are not shown - android

I had a RecyclerView in ScrollView like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--other stuff-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
<!--other stuff-->
</ScrollView>
And the RecyclerView's item is a RelativeLayout, inside of which there is an EditText and other views. The layout_height of that RelativeLayout and EditText is both wrap_content. User can input into that EditText without any limit of length/lines so that each item's height is different.
Then I found that getItemCount() in Adapter returns true value but onBindViewHolder() is called of wrong times(less than it should be), thus not enough to show all items.
I found that this will happen only if I wrote recyclerView.setNestedScrollingEnabled(false). But I cannot remove this line. Because if I did so, the RecyclerView won't scroll smoothly and is not harmonious with other views inside ScrollView and ScrollView itself.
This occurs on 6.0 but not on 4.1.
I communicated with Google at this page: https://code.google.com/p/android/issues/detail?id=213914 and he told me this is a bug fix for RecyclerView. You can visit that page so that you can understand the question and my goal better(There is a small sample project to show the problem there). I don't agree with him even now and I want to solve the problem. Please help, thank you in advance.

I found the solution myself: replace ScrollView with NestedScrollView and keep recyclerView.setNestedScrollingEnabled(false). I don't know if this is what NestedScrollView is made for but it works.
NOTICE:
NestedScrollView is not a child of ScrollView but of FrameLayout.
This solution will also bring some bugs with self-simulated adjustResize.

In my case, I replaced LineaLayout with RelativeLayout and it's solved the issue and all items have shown.

The answer is:
androidx.core.widget.NestedScrollView
In the first step, you need to create NestedScrollView element in XML:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// RecyclerViews should be located here
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Next, add the below attribute to recyclerView:
android:overScrollMode="never"
Then, the recyclerView will be as following:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
Finally, the whole the layout will be something like below, you can add other materials inside LinearLayout:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
// other materials
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Celebrate.............;)

The best solution is to keep multiple Views in a Single View / View Group and then keep that one view in the SrcollView. ie.
Format -
<ScrollView>
<Another View>
<RecyclerView>
<TextView>
<And Other Views>
</Another View>
</ScrollView>
Eg.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="any text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="any text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
Another Eg. of ScrollView with multiple Views
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/CategoryItem"
android:textSize="20sp"
android:textColor="#000000"
/>
<TextView
android:textColor="#000000"
android:text="₹1000"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:textColor="#000000"
android:text="so\nugh\nos\nghs\nrgh\n
sghs\noug\nhro\nghreo\nhgor\ngheroh\ngr\neoh\n
og\nhrf\ndhog\n
so\nugh\nos\nghs\nrgh\nsghs\noug\nhro\n
ghreo\nhgor\ngheroh\ngr\neoh\nog\nhrf\ndhog"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Related

Not able show Top & bottom items in recyclerView

I am using recyclerview in my project but bottom items are not displayed in recyclerview.
I tried ScrollView but my app is crashing it shows java.lang.IllegalStateException: ScrollView can host only one direct child this error.
Here is my code
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyler_transaction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout></FrameLayout>
<ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:id="#+id/rcview"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
Implement your RecyclerView in this manner. You dont need ScrollView to add recyclerview. Recyclerview can scroll by itself.
It will be good of you can add your whole xml and Adapter code.
I think you use the recyclerview as parent layout that this work is wrong, because recyclerview in android just get a adapter that it, and you most use the container layout like scrollbars for show another layout inside it.
You have added more than one ViewGroup as a child of your ScrollView. ScrollView must contain at most one child in order to properly calculate the height of the view.
Below sample code is wrong:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....
....
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....
....
</LinearLayout>
</ScrollView>
In order to solve the problem, you can use the below sample code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- here add your views -->
....
....
</LinearLayout>
</ScrollView>

Handle scrolling of a huge Layout

I'm in stuck with my layout with a lot of recyclerViews (4).
If three recyclers have up to 20 items per each and they are GONE by default in xml, then fourth recycler has up to 100-400 items (not more) which are dynamically changing in code and it is VISIBLE by default.
I need to scroll (smoothly scroll, ofc) all of menu (layout) including all of it elements.
I was trying NestedScrollView, ScrollView for all layout, for pieces of layout, for recyclerViews.
I was trying this for RecyclerView: app:layout_behavior="#string/appbar_scrolling_view_behavior"
I was trying:
layoutManager.setAutoMeasureEnabled(true); //deprecated
recyclerView.setNestedScrollingEnabled(false);
I was trying android:descendantFocusability="blocksDescendants" for Nested
I was trying android:nestedScrollingEnabled="false" for RecyclerView
I was trying adapter.setHasStableIds(true);
I was trying to combine all of this things from stackoverflow and other resources.
I have achieved scrolling which I want just by simple adding NestedScrollView after my rootLayout (not smooth, but works correct), but only in AVD, real devices with up to 3GB RAM cannot handle adding of NestedScrollView - devices are getting infinite black screen and empty Logs.
Maybe I was trying to do something else and I've forgotten to type about them here. Comment about some another similar fixes and I will reply.
How I can achieve smooth scrolling all of rootLayout elements?
I know that rule about scrolling views inside of another scrolling views, but I need to scroll all of my scrollable recyclers.
<?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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:id="#+id/rootLayout"
android:background="#color/float_transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/LLMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/gray21"
>
<RelativeLayout
android:id="#+id/RLTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<View
android:id="#+id/BluecolorView"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#color/colorBlue"
>
</View>
<View
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#color/white"
android:layout_below="#+id/BluecolorView"
>
</View>
<FrameLayout
android:id="#+id/FLIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
>
<ImageView
android:id="#+id/logoinmenu"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="#string/logo"
android:src="#drawable/logoicon"
>
</ImageView>
</FrameLayout>
</RelativeLayout>
<TextView
android:id="#+id/TVUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="#dimen/textViewTextSize"
android:text=""
android:layout_gravity="center"
android:textColor="#color/white"
>
</TextView>
<LinearLayout
android:id="#+id/LLAllM"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
>
<LinearLayout
android:id="#+id/LL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible"
>
<LinearLayout
android:id="#+id/LLIVandBTG"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
>
<ImageView />
<Button
android:id="#+id/BTGenresRV"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#color/float_transparent"
android:text="#string/genres"
android:textAllCaps="false"
android:textColor="#color/white"
android:gravity="start|top"
android:layout_marginStart="5dp"
>
</Button>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/RVGenresList"
android:layout_width="match_parent"
android:layout_height="150dp"
android:visibility="gone"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
Here are three more similar to "<LinearLayout android:id="#+id/LL" blocks...
</LinearLayout>
</LinearLayout>
</LinearLayout>
UPD:
I've forgotten to add that all of this handling by a public class MenuFragment extends Fragment implements View.OnTouchListener
Fragment are located in ActivityName extends AppCompatActivity
UPD2:
Partially fixed it by adding ScrollView after rootLayout and static height to recyclers.
Will see, maybe this is the best solution and I will provide full code in answer.
UPD3: This is because of wrap_content and match_parent I was not able to scroll like I need.

RecyclerView content goes behind and not over TextView above

Consider this video from material design on drag & dropping items:
Material design reordering list
In the video you see a RecyclerView and above it a TextView with the text "Playlist". When the row is dragged up you see it going over the Playlist.
In my code the row goes behind the Textview. I've put RecyclerView's layout_height to match_parent. And I used a FrameLayout and placed the TextView below the RecyclerView. Why isn't it going over it?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/general_margin"
android:text="#string/activity_bible_order_explanation"
android:layout_gravity="start|top" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:layout_marginTop="96dp"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</FrameLayout>
Use Constraint layout as a parent layout and add textview at the top by giving top constraints to the textview. then add
recyclerview's top constraint to the the bottom of textview and recyclerview bottom constraint to the bottom of parent then set height 0 it will work
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:padding="#dimen/general_margin"
android:text="#string/activity_bible_order_explanation"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/txtTitle"
android:background="#android:color/transparent"
android:layout_marginTop="96dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.constraintlayout.widget.ConstraintLayout>
Have you tried elevation? the problem might be that in the z axis the TextView is higher than the RecyclerView. try adding android:elevation="10dp" or higher... like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/general_margin"
android:text="#string/activity_bible_order_explanation"
android:layout_gravity="start|top" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp" (if it doesn't work try maybe higher elevation, 20dp etc.)
android:background="#android:color/transparent"
android:layout_marginTop="96dp"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</FrameLayout>
Hope it works for you (: let me know!
What is the parent layout of this?
Because you set match_parent in recyclerview and list have many content that's why this issue facing.
Please give fix height or use relative layout and apply position above of text view in recyclerview
Problem with your layout code:
You're using a FrameLayout
Inside FrameLayout, you're also using top margin on your RecyclerView
android:layout_marginTop="96dp" <-- This causing the issue.
Solution:
You should LinearLayout instead of FrameLayout. And, also set LinearLayout's orientation as vertical.
android:orientation="vertical"
Also remove this line from your RecyclerView:-
android:layout_marginTop="96dp"
Solution 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"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="Hello World"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
The issue is not that the dragged view is going behind the TextView but, rather, the dragged view is not being drawn outside the bounds of the RecyclerView. The effect is the same.
To allow the RecyclerView to draw outside of itself, set the following for the parent of the RecyclerView:
android:clipChildren="false"
For the RecyclerView set
android:clipToPadding="false"
That should solve the problem.
The RecyclerView is above the text view in your FrameLayout. Currently, it appears that the underlying TextView is above the RecyclerView as you have given the background for the RecyclerView as:
android:background="#android:color/transparent"
To make this work as normal, either remove this line or change the background of RecyclerView to any value other than transparent.
There is 1 more issue. You need to place the recycler view first. Try this:
<?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"
android:id="#+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<TextView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="Hello World"/>
</LinearLayout>

Two RecyclerViews in one layout is not working because one is missing in Android

I am developing an Android app. In my app, I want to use two RecyclerViews in one layout. I used LinearLayout to wrap up RecyclerViews because of this Stack Overflow question (Two RecyclerViews under each other in one layout).
As you can see the answer says, to use LinearLayout and set RecyclerViews height to wrap_content. I followed it. But when I run only one RecyclerView is appear and one is missing.
This is the screenshot:
As you can see, only on RecyclerView is appeared.
This is my XML layout:
<LinearLayout
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
</LinearLayout>
I tried this as well. Nothing appears on screen:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/ai_rc_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="#color/white"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/ai_rc_reviews_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"/>
</LinearLayout>
</ScrollView>
How can I fix my code to use two RecyclerViews in single layout. Is there any better way to do it?
Try using the layout_weight property instead of wrap_content. Give both RecyclerViews same weight and change height to 0dp.
<LinearLayout
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="#+id/ai_rc_reviews_2"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Generally it's not a good idea to have two scroll containers one inside the other if they scroll along the same axis. That behavior will most likely cause confusion with the user. Instead, if you are 100% sure that you need to have two scrolling containers vertically stacked - and please try not to do it if not 100% necessary, you should use fixed heights for each container as it will positively impact overall performance of the created layout.
<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"
android:scrollbars="none"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- Usual Size -->
<LinearLayout
android:id="#+id/usualSize_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical"
>
<TextView
android:id="#+id/usualSize_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="size"
android:textSize="#dimen/font_15"
android:textColor="#color/color_999999"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/usualSize_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height"
/>
</LinearLayout>
<!-- MarkImage -->
<LinearLayout
android:id="#+id/mark_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical"
>
<TextView
android:id="#+id/mark_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mark"
android:textColor="#color/color_999999"
android:textSize="#dimen/font_15"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"
/>`
<android.support.v7.widget.RecyclerView
android:id="#+id/mark_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Here we should think twice the WRAP_CONTENY ,so we should in the file:build.gradle.
Please update version of a library in gradle file :
compile 'com.android.support:recyclerview-v7:23.2.1'
and higher version.please check your version.
How do I make WRAP_CONTENT work on a RecyclerView
<!-- Usual Size -->
<LinearLayout
android:id="#+id/usualSize_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical">
<TextView
android:id="#+id/usualSize_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="size"
android:textSize="#dimen/font_15"
android:textColor="#color/color_999999"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/usualSize_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height"/>
</LinearLayout>
<!-- MarkImage -->
<LinearLayout
android:id="#+id/mark_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_f5f5f5"
android:layout_marginLeft="#dimen/common_10"
android:layout_marginTop="#dimen/common_10"
android:orientation="vertical">
<TextView
android:id="#+id/mark_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mark"
android:textColor="#color/color_999999"
android:textSize="#dimen/font_15"
android:layout_marginTop="#dimen/common_16"
android:layout_marginBottom="#dimen/common_10"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/mark_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="#dimen/list_height"/>
</LinearLayout>
</LinearLayout>
Here we should think twice the WRAP_CONTENY, so we should in the file:build.gradle.
Please update version of a library in gradle file :
compile com.android.support:recyclerview-v7:23.2.1
and higher version. please check your version.
How do I make WRAP_CONTENT work on a RecyclerView
Just in case someone has two RecyclerViews and other views inside one Srcollview,
if you have problem that the first recyclerview won't scroll up or second one part missing,
if you used LinearLayout to contain these RecyclerViews , try to use relativeLayout instead, which solved my problem.

Android ScrollView automatically scrolls to the bottom of the view

I have created one activity which is containing one map, image and another text view, and I have added "scrollview" tag for it. But after the activity starts it scrolls to the end of the page automatically. Please tell me why this happens and how to stop it from moving to end so I can scroll it by myself.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.radikallab.earch.DetailsActivity"
android:background="#drawable/background10">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="Title"
android:textStyle="italic"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/background4"
android:id="#+id/iv"/>
<TextView
android:id="#+id/rat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Title"
android:textStyle="italic"/>
<TextView
android:id="#+id/addr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Title"
android:textStyle="italic"/>
<WebView
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_marginTop="10dp"
android:id="#+id/webView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
I also face the same scenario once but adding the descendantFocusability attribute to the ScrollView's containing LinearLayout, solve my issue.
android:descendantFocusability="blocksDescendants"
you can use this as :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
Set android:focusableInTouchMode="true" in your linear layout:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:focusableInTouchMode="true"
android:layout_height="match_parent">
In case you do want to set this manually using Java;
Try this- it really works:
Use FOCUS_UP to scroll to the top and FOCUS_DOWN to scroll it to the Bottom.
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(View.FOCUS_UP);
}
What worked for me is a combination of the answers from Punit Sharma and FAЯAƸ.
My issue was a scrollable view (RecyclerView) inside another scrollable view (NestedScrollView) -- same as your WebView inside a ScrollView.
Wrapping my inner scrollable view inside a FragmentLayout with attribute android:descendantFocusability="blocksDescendants" solved my auto-to-bottom-scrolling issue.
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
...>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/image_gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Actually i found a simple answer for this just add "setfocusable(false)" in the associated java file.....in this case the "webview" coz its scroll there first....so add "webview.setfocusable(false)" in the associated webview java class.
Actually, we will face the scrolling problem if child inside ScrollView supports scrolling too like ListView and in your case WebView.
I found a similar question with some workaround. It supports vertical scrolling but horizontal scrolling is not supported if HTML page exceeds the WebView width.
See this for reference.

Categories

Resources