Reputation: 1352
I set RecyclerView
in XML file as gone as you can see in the codes.
After get updates from server I want to show them when I set RecyclerView
visibility from GONE
to VISIBLE
it will scroll down all the page to reach this RecyclerView
.
How I can fix this issue or this there any better solution to use ShimmerLayout
and ``RecyclerView``` without happening this.
This is part of my code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView"
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">
// Some rows are here
// ...
<LinearLayout
android:id="@+id/news_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
// Another Row
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/latest_news_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
<LinearLayout
android:id="@+id/news_shimmer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:visibility="visible">
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
<include layout="@layout/shimmer_news_row" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Upvotes: 1
Views: 261
Reputation: 446
I solved it by wrapping recyclerview with nestedscrollview.
<androidx.core.widget.NestedScrollView
android:id="@+id/layout_recycler_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.core.widget.NestedScrollView>
Upvotes: 1
Reputation: 468
Don't set GONE when you launched activity make it VISBILE by default. then data load on recycler view it will not recycle
Upvotes: 1