Android AppBarLayout去掉底下阴影

出现情景:
在CoordinatorLayout和AppBarLayout结合使用的时候经常需要一个tablayout去吸顶,但是这时候就出现了一种elevation这个属性设置了外阴影那种情况,为了达到UI需求,常常需要去掉阴影,这时候我们需要配套给com.google.android.material.appbar.AppBarLayout设置属性即可解决

代码示例:

android:background="@color/transparent"
app:elevation="0dp"

注意:elevation属性必须是app的,android的无效

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
要将 AppBarLayout 与 RecyclerView 使用,需要在布局文件中将它们嵌套在一起。具体实现步骤如下: 1. 在布局文件中定义 AppBarLayout 和 Toolbar 控件,用于显示顶部工具栏和标题栏。 ```xml <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" /> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> ``` 2. 在 AppBarLayout 内部添加一个可折叠式的标题栏控件(CollapsingToolbarLayout),用于显示标题和背景图片等内容。 ```xml <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView android:id="@+id/image_view" android:layout_width="match_parent" android:layout_height="200dp" android:scaleType="centerCrop" android:src="@drawable/header_image" 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" /> </android.support.design.widget.CollapsingToolbarLayout> ``` 3. 在布局文件中定义 RecyclerView 控件,用于显示列表内容。 ```xml <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> ``` 4. 在相应的 Activity 或 Fragment 中获取 RecyclerView 对象,并设置 Adapter 和 LayoutManager。 ```java RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(layoutManager); ``` 5. 在 AppBarLayout 中设置滚动监听器(OnOffsetChangedListener),根据滚动距离和状态改变工具栏的样式、大小和位置等效果。 ```java AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout); appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { // 根据 verticalOffset 计算工具栏的高度和透明度等属性 // 更新工具栏的样式和位置等 } }); ``` 这样就可以实现一个带有 AppBarLayout 和 RecyclerView 的可滚动界面了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落魄的Android开发

感谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值