-
Notifications
You must be signed in to change notification settings - Fork 265
RecyclerView
Etienne Lawlor edited this page Feb 1, 2015
·
4 revisions
The example below demonstrates QuickReturn view as a footer in a RecyclerView with a LinearLayoutManager and a snap animation
public class QuickReturnFooterRecyclerViewFragment extends Fragment {
// region Member Variables
private String[] mValues;
private QuickReturnAnimationType mQuickReturnAnimationType;
private String mLayoutManagerType;
@InjectView(R.id.rv)
RecyclerView mRecyclerView;
@InjectView(R.id.quick_return_tv)
TextView mQuickReturnTextView;
// endregion
// region Constructors
public static QuickReturnFooterRecyclerViewFragment newInstance(Bundle extras) {
QuickReturnFooterRecyclerViewFragment fragment = new QuickReturnFooterRecyclerViewFragment();
fragment.setRetainInstance(true);
fragment.setArguments(extras);
return fragment;
}
public static QuickReturnFooterRecyclerViewFragment newInstance() {
QuickReturnFooterRecyclerViewFragment fragment = new QuickReturnFooterRecyclerViewFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public QuickReturnFooterRecyclerViewFragment() {
}
// endregion
// region Lifecycle Methods
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_recyclerview_quick_return_footer, container, false);
ButterKnife.inject(this, view);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mValues = getResources().getStringArray(R.array.countries);
CountriesLinearLayoutAdapter countriesLinearLayoutAdapter = new CountriesLinearLayoutAdapter(getActivity(), Arrays.asList(mValues));
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), null));
mRecyclerView.setAdapter(countriesLinearLayoutAdapter);
int footerHeight = getActivity().getResources().getDimensionPixelSize(R.dimen.footer_height);
QuickReturnRecyclerViewOnScrollListener scrollListener = new QuickReturnRecyclerViewOnScrollListener.Builder(QuickReturnViewType.FOOTER)
.footer(mQuickReturnTextView)
.minFooterTranslation(footerHeight)
.isSnappable(true)
.build();
mRecyclerView.setOnScrollListener(scrollListener);
}
@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.reset(this);
}
// endregion
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
<com.etiennelawlor.quickreturn.views.CustomFontTextView
android:id="@+id/quick_return_tv"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="@color/transparent_black_ninty"
android:gravity="center"
android:text="@string/footer"
android:textColor="@android:color/white"
android:textSize="22sp"
app:textFont="Roboto_Bold" />
</RelativeLayout>