效果图:
实现步骤:
第一步:依赖包:implementation 'com.androID.support:design:28.0.0'
第二步:定义 activity_main.xml文件 内容如下:<?xml version="1.0" enCoding="utf-8"?><androID.support.design.Widget.CoordinatorLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <androID.support.design.Widget.AppbarLayout androID:ID="@+ID/appbar" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar" > <androID.support.design.Widget.CollapsingToolbarLayout androID:layout_wIDth="match_parent" androID:layout_height="200dp" app:contentScrim="?attr/colorPrimary" androID:background="@mipmap/ic_launcher" app:layout_scrollFlags="scroll|exitUntilCollapsed"> </androID.support.design.Widget.CollapsingToolbarLayout> </androID.support.design.Widget.AppbarLayout> <androID.support.design.Widget.floatingActionbutton androID:ID="@+ID/my_head" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" app:layout_anchor="@ID/appbar" app:layout_anchorGravity="bottom|center" app:elevation="6dp" androID:clickable="true" app:borderWIDth="0dp" androID:backgroundTint="#FFEB3B" app:ripplecolor="#832B2B2B" androID:layout_marginBottom="20dp" androID:layout_marginRight="20dp" app:pressedTranslationZ="12dp" /> <androID.support.v4.Widget.nestedScrollVIEw androID:layout_wIDth="match_parent" androID:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_vIEw_behavior" > <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="vertical" > <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="200dp" androID:background="#2196F3" androID:textcolor="#FFFFFF" androID:textSize="28sp" androID:gravity="center" androID:layout_marginBottom="10dp" /> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="200dp" androID:background="#2196F3" androID:textcolor="#FFFFFF" androID:textSize="28sp" androID:gravity="center" androID:layout_marginBottom="10dp" /> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="200dp" androID:background="#2196F3" androID:textcolor="#FFFFFF" androID:textSize="28sp" androID:gravity="center" androID:layout_marginBottom="10dp" /> </linearLayout> </androID.support.v4.Widget.nestedScrollVIEw></androID.support.design.Widget.CoordinatorLayout>
结论:
CollapsingToolbarLayout 是不能独立存在的,它必须只能作为AppbarLayout 的子布局来使用,这里先调整AppbarLayout 的告诉来适应图片。
总结以上是内存溢出为你收集整理的Android——可折叠式的标题栏全部内容,希望文章能够帮你解决Android——可折叠式的标题栏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)