Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header Decoration only shows after scroll #3

Closed
abangkis opened this issue Sep 4, 2016 · 2 comments
Closed

Header Decoration only shows after scroll #3

abangkis opened this issue Sep 4, 2016 · 2 comments

Comments

@abangkis
Copy link

abangkis commented Sep 4, 2016

Hi, first thanks for the great samples.

I tried your header decorator in my application, it has a tab layout and inside the tab layout there's a fragment. I'm using the header layout in the recycler view in that fragment. The problem is that when the fragment is first created the item isn't decorated, but after scrolling down and back up again the header is shown. Maybe you can shed some light why that happening.

Here's the attached gif

header view

Here's the code, the initRecyclerView is called from Fragment.onCreateView(). Thanks for the help

``
private void initRecyclerView(View v) {
recyclerView = (RecyclerView) v.findViewById(R.id.recyclerview);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    recyclerView.setHasFixedSize(true);

    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL_LIST));

    // use a linear layout manager
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity().getApplicationContext(), new RecyclerItemClickListener.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Trayek trayek = adapter.getItem(position);

            if(trayek != null) {
                Intent intent = new Intent(getActivity().getApplicationContext(), AngkotRouteActivity.class);
                intent.putExtra("bus_code", trayek.getVehicleNo());
                intent.putExtra("bus_name", trayek.getVehicleName());
                intent.putExtra("id_trayek", trayek.getId());
                startActivity(intent);

            }
        }
    }));

    recyclerView.addItemDecoration(HeaderDecoration.with(recyclerView)
            .inflate(R.layout.header_damri)
            .parallax(1f)
            .dropShadowDp(4)
            .build());
}

``

@bleeding182
Copy link
Owner

I'm sorry I couldn't find the time to look into this issue yet

I'm guessing this could be due to the ViewPager, preparing the fragment in the background, before it gets displayed. It could be that the height of the recyclerview is measured as 0 and thus drawing the decoration wrong (If you have a look at this methog here)

I believe you would do best to just attach a debugger and step it through :)

@abangkis
Copy link
Author

abangkis commented Sep 9, 2016

Hi, no problem. I already implement it using another way, but i really-really like the item decoration approach. I'll see if i can understand the part that you linked.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants