Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoordinateLayout collapse LinearLayout with childviews

Hey there I have a layout with mainly two Views, the one at the top is for selection and the bottom one shows the content (ScrollView with Listview). My desired behavior is that when I scroll through the content the upper View collapses or expands (CollapsingToolbarLayout like).

At the moment I realized the whole layout with layout_weights and I'm not sure how to correctly implement the CoordinateLayout for resizing the the View.

Layout is like this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<LinearLayout
    android:id="@+id/preview_wrapper"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="0dp">

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager_preview"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.4">

</android.support.v4.view.ViewPager>


<CustomIndicator
    android:id="@+id/pager_indicator"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.1"/>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5">

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/view_pager_preview">
<ScrollView
    android:id="@+id/scroll_view"
    android:focusable="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


</ScrollView>
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>

Would be glad if someone could explain how to implement CoordinateLayout, CollapsingToolbarLayout and AppBarLayout in this case.

like image 378
David Avatar asked Jan 27 '26 15:01

David


1 Answers

If you want your top ViewPager to collapse, I'd put it in the top section of the CoordinatorLayout. Something like this :

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
    android:id="@+id/main.appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">
    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll"
        app:contentScrim="?attr/colorPrimary"
        app:layout_collapseMode="pin">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:background="@color/transparent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="parallax">
        </android.support.v7.widget.Toolbar>
      <android.support.v4.view.ViewPager
        android:id="@+id/viewpagerTop"
        android:background="@android:color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
    android:id="@+id/viewpagerBottom"
    android:background="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"/>

like image 96
NSimon Avatar answered Jan 30 '26 06:01

NSimon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!