kanytu / android-parallax-recyclerview Goto Github PK
View Code? Open in Web Editor NEWAn adapter which could be used to achieve a parallax effect on RecyclerView.
License: Apache License 2.0
An adapter which could be used to achieve a parallax effect on RecyclerView.
License: Apache License 2.0
Hi I 'm using the adapter in a Fragmet and I can not get it to work, the resulting view is empty.
public class PlaylistPreviewFragment extends Fragment {
protected RecyclerView recyclerPlaylistTracks;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.playlist_preview_fragment,container,false);
recyclerPlaylistTracks = (RecyclerView)view.findViewById(R.id.playlist_tracks);
final List<String> content = new ArrayList<>();
for (int i = 0; i < 50; i++) {
content.add("item " + i);
}
final ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<String>(content) {
@Override
public void onBindViewHolderImpl(RecyclerView.ViewHolder viewHolder, ParallaxRecyclerAdapter<String> adapter, int i) {
TrackViewHolder trackViewHolder = (TrackViewHolder)viewHolder;
trackViewHolder.setTitle(content.get(i));
}
@Override
public RecyclerView.ViewHolder onCreateViewHolderImpl(ViewGroup viewGroup, final ParallaxRecyclerAdapter<String> adapter, int i) {
return new TrackViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.playlist_track_layout, viewGroup, false));
}
@Override
public int getItemCountImpl(ParallaxRecyclerAdapter<String> adapter) {
return content.size();
}
};
adapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() {
@Override
public void onClick(View v, int position) {
Toast.makeText(getActivity(), "You clicked '" + position + "'", Toast.LENGTH_SHORT).show();
}
});
recyclerPlaylistTracks.setLayoutManager(new LinearLayoutManager(getActivity()));
View header = inflater.inflate(R.layout.playlist_tracks_header, recyclerPlaylistTracks, false);
adapter.setParallaxHeader(header, recyclerPlaylistTracks);
adapter.setData(content);
recyclerPlaylistTracks.setAdapter(adapter);
return view;
}
static class TrackViewHolder extends RecyclerView.ViewHolder{
private TextView title;
public TrackViewHolder(View itemView) {
super(itemView);
title = (TextView)itemView.findViewById(R.id.title);
}
public void setTitle(String title) {
this.title.setText(title);
}
public String getTitle() {
return title.toString();
}
}
}
can you help me please?
onCreateViewHolderImpl and onBindViewHolderImpl are never called.
Thanks and greetings
Hi,
why not consider to implement methods that allows parallax factor editing?
I am trying to create an instance of your adapter by extending it to load arraylist of custom objects from the internet, initially it ll have nothing but later it ll be filled with data.
I get this error saying 'no default constructor available' what would be the optimal way to load nothing initially and then load data inside the parallax from the internet, thanks for your reply in advance
The problem is quite simple to explain, but I don't know how to solve it...
-> When I start scrolling the percentage and offset are okay, but when I pass the 100% (in the log it reaches 0.99722224) it goes down to 54% and start going up again as I keep scrolling down.
Is it possible to make RecyclerView
content overlaps little bit upon the header, something like Google's Play Newsstand??
I have tried to mimic that behavior by adding an additional offset to setClipY
function, I could make contents overlap header but the problem is the header disappears early when first item reaches top edge of the view port.
Also the header appears with additional offset when scrolling down again.
Code:
public void setClipY(int offset) {
int tmpOffset = (int)(offset * 0.7);
mOffset = offset + tmpOffset;
invalidate();
}
Hi, I've put the recyclerview with parallax header inside a viewpager which have 4 fragment (0 - 3). The problem occurs when the recyclerview is scrolled until the image collapsed, then the viewpager change position from 0 - 2. When i return back to the fragment (position 0) and scrolled back up the image are gone (white blank).
I set the adapter.setParallaxHeader() inside the onCreateView. Is this a bug or am i putting it in the wrong place? Thank you.
I'm having mu custom viewholder which extends RecyclerView.ViewHolder and I'm dynamically updating the recyclerview. It's showing error while Overriding onBindViewHolder. I have used an Interface 'AccountInfo' instead of 'String' type.
Here's my Adapter code:
public class AccountDetailAdapter extends ParallaxRecyclerAdapter<AccountDetailAdapter.AccountDetailViewHolder> {
private LayoutInflater inflater;
private Context context;
List<AccountInfo> data = Collections.emptyList();
public AccountDetailAdapter(Context context, final List<AccountInfo> data) {
super(new ArrayList<AccountInfo>());
this.context = context;
inflater = LayoutInflater.from(context);
this.data = data;
implementRecyclerAdapterMethods(new RecyclerAdapterMethods() {
@Override
public void onBindViewHolder(AccountDetailViewHolder viewHolder, int i) {
AccountInfo current = data.get(i);
viewHolder.pName.setText(current.personName);
viewHolder.pBalance.setText(current.personBalance);
viewHolder.pIcon.setImageDrawable(current.personIconId);
}
@Override
public AccountDetailViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = inflater.inflate(R.layout.account_row, viewGroup, false);
AccountDetailViewHolder holder = new AccountDetailViewHolder(view);
return holder;
}
@Override
public int getItemCount() {
return data.size();
}
});
}
class AccountDetailViewHolder extends RecyclerView.ViewHolder {
TextView pName;
TextView pBalance;
ImageView pIcon;
public AccountDetailViewHolder(View itemView) {
super(itemView);
pName = (TextView) itemView.findViewById(R.id.personName);
pBalance = (TextView) itemView.findViewById(R.id.personBalance);
pIcon = (ImageView) itemView.findViewById(R.id.personIconId);
itemView.setClickable(true);
}
}
}
And in calling super(new ArrayList()), it says "ParallaxRecyclerAdapter (java.util.List<com.example.myapp>.AccountDetailAdapter.AccountDetailViewHolder) in ParallaxRecyclerAdapter cannot be applied to java.util.ArrayList<com.example.myapp>.AccountInfo.
How do I port to my own ViewHolder?
For example:
ImageView imgView = (ImageView) ....findViewById(R.id.my_image_view);
Hello. Want to know, can i add another header? a header that is not inside the parallax header. Where should i do that. Thank you.
Hi!
I've been using your library for a recycler view with a map header. Is there an option for the reclerview to scroll only when touching any element but the header? in order to make the map touchable?
Thanks
Wouldn't it be more appropriate if instead of having a method that asks for the implementation, to have them overriden?
I mean, instead of this:
ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<>(content);
adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {
// implemented methods
}
This:
ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<>(content) {
// implemented methods
}
However i implement it, i always get first item empty.
Hello, guys
I found such a bug:
header disappears, and then abruptly appears and the description is superimposed on it (see image)
the mRecyclerView.computeVerticalScrollOffset()
on 99 line produces a value much larger than mHeader.getHeight()
if you write such a piece of code, it will work out correctly
super.onScrolled(recyclerView, dx, dy);
if (mHeader != null) {
float verticalScrollOffset = MathUtils.min(mRecyclerView.computeVerticalScrollOffset(),
mHeader.getHeight());
translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeader ?
verticalScrollOffset : mHeader.getHeight());
}
Hi Pedro -- this looks exactly like what I'm looking for based on. Unfortunately, the provided instructions are hard for me to understand because I'm new to Android development. Would you mind creating an example app to show how it is used? I appreciate your consideration.
I got strange issue, not sure if its related to #7 but I guess it has something to do with the linear layout manager.
When the recycler view scrolled down till the header being totally clipped...at that point data insertion or removing cause the recycler view to scroll to top.
While it's working as expected if the header view is not totally clipped.
when I do scroll with my fingers everything works fine, but if I want to do it programmatic and for example go to the last element with something like:
recyclerview.scrollToPosition(adapter.getItemCount()-1);
it doesn't work, even with the sample code on this repo, it scrolls but header dissapear when i scroll up again to the same place.
I haven't test the follow code, but I see this link:
http://stackoverflow.com/questions/8734001/programmatically-translate-view-pre-honeycomb
public void translateHeader(float of) {
float ofCalculated = of * SCROLL_MULTIPLIER;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mHeader.setTranslationY(ofCalculated);
} else {
TranslateAnimation anim = new TranslateAnimation( 0, 0,ofCalculated,ofCalculated);
anim.setFillAfter(true);
anim.setDuration(0);
mHeader.startAnimation(anim);
}
.....
I get this crash:
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4309)
at android.view.ViewGroup.addView(ViewGroup.java:4145)
at android.view.ViewGroup.addView(ViewGroup.java:4117)
at com.poliveira.parallaxrecyclerview.ParallaxRecyclerAdapter.setParallaxHeader(ParallaxRecyclerAdapter.java:97)
and here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="com.mango.android.common.model.Dialect"/>
<variable name="dialect" type="com.mango.android.common.model.Dialect"/>
</data>
<ImageView android:id="@+id/iv_header"
android:layout_alignParentTop="true"
android:layout_height="@dimen/hero_image_height"
android:layout_width="match_parent"
android:background="@color/ripe_orange"
app:headerImageSrc="@{Dialect.PREFIX_HEADER + dialect.getHeaderName}"/>
</layout>
Hi,
I was trying to implement parallax scrolling using this awesome library. But I ran into some problems. Am not sure I'm doing this right(first time android programmer). I'm getting this on adding parallaxheader.
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() >on the child's parent first.
I'll just give you a brief idea of what I did. I have a chart which is the header.
So I extended your ParallaxRecyclerAdapter with a custom constructor, overrode some methods, and named it StatsAdapter
public StatsAdapter(LineChartData mChartData, final List<StatsItem> mListData) {
super(mListData);
this.mListData = mListData;
this.mChartData = mChartData;
implementRecyclerAdapterMethods(this);
}
And overrode setParallaxHeader like this
public void setParallaxHeader(View header, RecyclerView view) {
LineChartView chart = (LineChartView) header.findViewById(R.id.chart);
chart.setLineChartData(mChartData);
formatChart(chart);
super.setParallaxHeader(header, view);
}
And in the Fragment from which I'm loading the recyclerview, I did this
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.stats_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mStatsAdapter = new StatsAdapter(mChartData, mListData);
mHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_chart_detail,mRecyclerView,false);
mStatsAdapter.setParallaxHeader(mHeaderView, mRecyclerView);
mRecyclerView.setAdapter(mStatsAdapter);
Any idea why I'm getting this error?
just install sample project. Run on an emulator. Open Memory Monitor. Scroll up and down with several times. Memory is growing. Sometimes GC start, but cannot release more memory. Always call GC.
Any idea on this issue?
Thanks
First I want to say, Wonderful work!
Now I have this need in my project. One of my RecylerView's LayoutManger is a GridLayoutManger,When I look the setOrientation method, except the "LinearLayout.HORIZONTAL" and "LinearLayout.VERTICAL", it will throw a Exception called "invalid orientation".
Will it support the GridView's style in the future? thx.
Hi!
I want set the image inside the activity. Can you tell me how?
Thanks in advance
02-03 15:50:28.112 28916-28916/com.hupu.shihuo E/alpha: percentage=0.7039338
02-03 15:50:28.112 28916-28916/com.hupu.shihuo E/alpha: 180
02-03 15:50:28.112 28916-28916/com.hupu.shihuo E/hexAlpha: b4
02-03 15:50:28.148 28916-28916/com.hupu.shihuo E/alpha: percentage=0.8688751
02-03 15:50:28.148 28916-28916/com.hupu.shihuo E/alpha: 222
02-03 15:50:28.148 28916-28916/com.hupu.shihuo E/hexAlpha: de
02-03 15:50:28.151 28916-28916/com.hupu.shihuo E/alpha: percentage=0.8730159
02-03 15:50:28.151 28916-28916/com.hupu.shihuo E/alpha: 223
02-03 15:50:28.151 28916-28916/com.hupu.shihuo E/hexAlpha: df
02-03 15:50:28.185 28916-28916/com.hupu.shihuo E/alpha: percentage=0.97722566
02-03 15:50:28.185 28916-28916/com.hupu.shihuo E/alpha: 249
02-03 15:50:28.185 28916-28916/com.hupu.shihuo E/hexAlpha: f9
02-03 15:50:28.210 28916-28916/com.hupu.shihuo E/alpha: percentage=100.0
02-03 15:50:28.210 28916-28916/com.hupu.shihuo E/alpha: 25500
02-03 15:50:28.210 28916-28916/com.hupu.shihuo E/hexAlpha: 639c
percentage 's value shoud be 1.0 at the last!
Hi. Have you tried to use the onScrollListener on the RecyclerView with this adapter?
In my case it is never called! For the rest everything works fine.
Hi,
How to achieve this layout?
bit.ly/1CKRIQM
Hello all,
I sucessfully imported your awesome lib, and nearly everything is working fine:
I have added a Google Map (Lite mode) in my header xml, like this:
and the current rendering is horrible: the map is too small:
I have tried to play by whanging every height I could, but the small header is really annoying and I don't see any option to change it.
How can i set bottom margin for the header?
I have a situation where I may or may not have a header. When I have a header, everything is fine. However, if I don't have a header, then things get strange.
onBindViewHolder() will not call my onBindViewHolderImpl() if the position is 0. However, onCreateViewHolderImpl() will still be called, expecting a ViewHolder to be created. The two methods have differing expectations.
There should be a consistent flow of events. You should either always handle position 0, regardless of if there's a header, or you should handle it if there is a header, and pass through like a regular RecyclerAdapter if not.
Is this possible to use this library using Gradle repositories?
It is possible to set min header height? I would like to have a header height between 100-200 dp
I want to change something that is inside my header layout (an Image View alpha) during scroll (just like he toolbar alpha thing). Is this possible?
Error:A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not find com.github.kanytu:android-parallax-recyclerview:v1.3.
Searched in the following locations:
https://jcenter.bintray.com/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.pom
https://jcenter.bintray.com/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.jar
file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/android/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.pom
file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/android/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.jar
file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/google/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.pom
file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/google/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.jar
Required by:
mytripeazzy:app:unspecified
I simply want to detect clicks over parallaxAdapter items.
Maybe I'm missing something, I can't get setOnClickEvent() to work.
mAdapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() {
@OverRide
public void onClick(View view, int i) {
//This is never called
}
});
Please note that mAdapter.setOnParallaxScroll(new ParallaxRecyclerAdapter.OnParallaxScroll() ... ) works perfectly and I have onBindViewHolderImpl(), onCreateViewHolderImpl(), etc. implemented and working inside the adapter impl
Hi i found that the header is missing when the content in the recycler view is empty. Could this behavior be removed?
RecyclerView method getAdapterPosition() needs to be Overriden, since it doesnt take the parallax view into calculations.
No need to emphasize that this method is extremely important when working with recycler view and its viewholders since on click methods should be implemented in view holders using getAdapterPosition and not using final positions returned by bindViewHolder method.
hello,
Thankyou for the library. It's working fine.
The thing I want to achieve is add a custom row or relative layout between header image & recyclerview. I have tried following this example http://stackoverflow.com/questions/26568087/parallax-header-effect-with-recyclerview#text. The example where the guy inserted a text " Hi, I'm new here " before test 1 & after header image.
The problem with my code is the first element of recylcerview is getting replaced by the custom row that I have created. This is the output http://s11.postimg.org/w31cmp3qb/detail.jpg . the "mobileapp" is the data in the recyclerview .mobileapp 0 is getting hidden or replaced by " MobileApp 0".
This is my code I am using
adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {
@OverRide
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,
int i) {
if (i == 0) {
((ViewHolder) viewHolder).title.setText(“MobileApp” + i);
((ViewHolder) viewHolder).ct.setText(“test”);
} else if (i > 0) {
((ViewHolder) viewHolder).title2.setText((“mobileapp” + i);
((ViewHolder) viewHolder). title3.setText(“”);
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(
ViewGroup viewGroup, final int i) {
final ViewHolder holder;
if (i == 3) {
holder = new ViewHolder(getLayoutInflater().inflate(
R.layout.row_recylceview_firstcard, viewGroup,
false), i);
} else {
holder = new ViewHolder(getLayoutInflater().inflate(
R.layout.row_recyclerview, viewGroup, false), i);
}
return holder;
}
@Override
public int getItemCount() {
return content.size();
}
});
please help
How can we add a zoom effect to the header? i.e. when scrolling down, it scales up.
HeaderLayoutManagerFixed and ParallaxRecyclerAdapter declare their package to be com.poliveira.parallaxrecycleradapter, but they are in the folder com.poliveira.parallaxrecyclerview. Which is right?
As I noticed you are overriding getItemViewType method. I wanted to know if you have suggestion for handling different type the rows.
how to add adapter class suppurate
Hi Pedro Oliveira,
I'm Using this library into my studio for an app. it really awesome and works fine and its too friendly. But in my project i just have functions like this.
The header image has
<android.support.v4.view.ViewPager
android:id="@+id/wallPaperPager"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:overScrollMode="never"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/wallpaperPageIndicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="10dp"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/logo"/>
rest of the things are into RecyclerView this is my java code to populate the header and things.
public void setParallaxAdapter() {
final ParallaxRecyclerAdapter adapter = new ParallaxRecyclerAdapter<>(contents);
adapter.setParallaxHeader(wallPaperLayout, recyclerView);
setImplementedMethods(adapter);
setScrollListener(adapter);
recyclerView.setAdapter(adapter);
}
In older version gradles project works fine. But today i migrated to android studio 3 with gradle version 3.1.4.
After migration same dependency added in build.gradle file.
but ParallaxRecyclerAdapter class not getting resolved. pls help me.
Am not able to add this library in my library project
Hi. Have you tried to scroll down to a position where the header is still visible and then rotate the device?
Then in my version the header is replaced by an empty view and the header is behind everything placed in the top. When I do a little scroll then everything is positioned correctly.
Hi There,
I have used your Parallax RecyclerView to load data from a cursor. I have modified the adapter to use a cursor instead of the List that is there by default.
I have modified the removeItem method too like below.
public void removeItem(int position) {
if (position < 0)
return;
notifyItemRemoved(position + (mHeader == null ? 0 : 1));
in the loaderFinished method, I swap the cursor and update the header values. in the existing adapter(not create a new adapter and swap adapter at recyclerview level)
This seems to be working perfectly, except for the UI. The values are updating correctly, but the list items seems to be overlapping the header after an item is removed.
This does not happen if the recyclerview is scrolled all the way to the top. But in any other position, it gives me something like this, with the list items overlapping the header (see below)
Let me know if you want the entire code of the Adapter I am using(the modified one)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.