android: Create layout which collapse on scrolling

前端 未结 3 1945
旧巷少年郎
旧巷少年郎 2021-01-02 11:37

I need a layout(view1) which on scrolling listview gets collapsed, so that listview have full screen height? \"Like

相关标签:
3条回答
  • 2021-01-02 12:05

    <android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
                <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/universe"
                    app:layout_collapseMode="parallax" />
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="hello"
                android:textSize="25dp"
                android:textStyle="bold|italic" />
        </android.support.v4.widget.NestedScrollView>
    
    </android.support.design.widget.CoordinatorLayout>
    

    0 讨论(0)
  • 2021-01-02 12:18

    Use collapsing Toolbar layout for your requirment.

    <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimaryDark"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:src="@drawable/abcd"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7" />
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/mtool"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            </android.support.v7.widget.Toolbar>
    
        </android.support.design.widget.CollapsingToolbarLayout>
    

    refer this link for help Design support library

    0 讨论(0)
  • 2021-01-02 12:26

    You can do that with android material design and make the AppBar collapse on scroll.Also add this attribute to your listView

    app:layout_behaviour="@string/appbar_scrolling_view_behavior"
    

    Use this link for more info here

    0 讨论(0)
提交回复
热议问题