Reputation: 23
In my application i want use SwipeRefreshLayout
and imageView
into NestedScrollView
I write below codes, but when run application show me many lag when scroll RecyclerView
and i'm not scroll items.
My xml code :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout 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.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<include layout="@layout/banner_layout" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
My java codes:
list.setLayoutManager(linearLayoutManager);
list.setHasFixedSize(true);
list.setNestedScrollingEnabled(false);
list.setAdapter(todayRecyclerAdapter);
How can i fix it and use this views?
Upvotes: 0
Views: 412
Reputation: 56
<CoordinatorLayout>
<SwipeRefreshLayout>
<RecyclerView>
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<Appbarlayout>
<Toolbar>
app:layout_scrollFlags="scroll|snap"/>
<Relative Layout>
app:layout_scrollFlags="scroll|snap"/>
<ImageView>
</Relative Layout>
</Appbarlayout>
</SwipeRefreshLayout>
</CoordinatorLayout>
Please try in these way it will work.
Upvotes: 0
Reputation: 408
Avoid nested scrolling whenever possible . You can design layout like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout 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.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
You can define data of adapter like this
.............
List<Object> objects=new ArrayList<>()
object.add(new ImageData('Image url'))
object.add(new Data('title','subtitle','date'))
.............
Since RecylerView
adapter supports different viewType
s you can use first position of adapter as
header view type and rest normal view type.
For that you can refer to this ans
Is there an addHeaderView equivalent for RecyclerView?
For a dynamic header, you can create a method like :
----
setHeaderAvailable(boolean isHeaderAvailable){
this.isHeaderAvailable=isHeaderAvailable
}
----
and adapter data will look like this:
---
List<Object> objects=new ArrayList<>()
if(imageUrl!=null){
adapter.setHeaderAvailable(true)
object.add(new ImageData('Image url'))
}else{
adapter.setHeaderAvailable(false)
}
object.add(new Data('title','subtitle','date'))
--
and update getItemViewType
method like this:
----
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position) && isHeaderAvailable)
return TYPE_HEADER;
return TYPE_ITEM;
}
---
Upvotes: 3
Reputation: 118
You have set this property before setAdapter
recyclerView.setNestedScrollingEnabled(false);
Upvotes: 0
Reputation: 178
replace your RecyclerView with this one..
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="200dp" />
Upvotes: 0