-
Notifications
You must be signed in to change notification settings - Fork 355
Unfoldable details usage
-
Create layout for your activity as following:
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" /> <View android:id="@+id/touch_interceptor_view" android:layout_width="match_parent" android:layout_height="match_parent" /> <FrameLayout android:id="@+id/details_layout" android:layout_width="match_parent" android:layout_height="match_parent"> ... </FrameLayout> <com.alexvasilkov.foldablelayout.UnfoldableView android:id="@+id/unfoldable_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout>
-
Initialize layout:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(...); mListView = (ListView) findViewById(R.id.list_view); mListView.setAdapter(...); mListTouchInterceptor = findViewById(R.id.touch_interceptor_view); mListTouchInterceptor.setClickable(false); mDetailsLayout = findViewById(R.id.details_layout); mDetailsLayout.setVisibility(View.INVISIBLE); mUnfoldableView = (UnfoldableView) findViewById(R.id.unfoldable_view); mUnfoldableView.setOnFoldingListener(new UnfoldableView.SimpleFoldingListener() { @Override public void onUnfolding(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(true); mDetailsLayout.setVisibility(View.VISIBLE); } @Override public void onUnfolded(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(false); } @Override public void onFoldingBack(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(true); } @Override public void onFoldedBack(UnfoldableView unfoldableView) { mListTouchInterceptor.setClickable(false); mDetailsLayout.setVisibility(View.INVISIBLE); } }); }
(Touch interceptor view is used to temporary disable list view scrolling)
-
Add back button handler:
@Override public void onBackPressed() { if (mUnfoldableView != null && (mUnfoldableView.isUnfolded() || mUnfoldableView.isUnfolding())) { mUnfoldableView.foldBack(); } else { super.onBackPressed(); } }
-
When user selects item in the list you should initialize details view with corresponding data. After that you can start unfolding details with:
mUnfoldableView.unfold(coverView, mDetailsLayout);
Where
coverView
is a view from the list that will be animated.
Note, that it must not be a list item's root layout, sinceUnfoldableView
will try to remove it from it's parent, andListView
andRecyclerView
will not behave correctly in this case. -
If your list adapter may be invalidated during details unfolding, you should ensure
UnfoldableView
is still using correctcoverView
. That mean you should find correctcoverView
(scrolling to it if necessary) and updateUnfoldableView
using:mUnfoldableView.changeCoverView(coverView);