当前位置: 移动技术网 > IT编程>移动开发>Android > Android实现滑动到顶部悬停的效果

Android实现滑动到顶部悬停的效果

2019年07月24日  | 移动技术网IT编程  | 我要评论

外汇图表,火影忍者全集国语版,无人岛物语

先来看下要实现效果图:

查阅资料后,发现网上大部分都是用这种方法实现的:

多写一个和需要悬浮的部分一模一样的layout,先把浮动区域的可见性设置为gone。当浮动区域滑动到顶部的时候,就把浮动区域b的可见性设置为visible。这样看起来就像悬浮在顶部不动了。

这里介绍的是另外一种方式:

使用design包中的控件

<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:fitssystemwindows="true"
 tools:context="com.peipei.app.mainactivity">

 <android.support.design.widget.appbarlayout
 android:layout_width="match_parent"
 android:layout_height="250dp">

 <android.support.design.widget.collapsingtoolbarlayout
  app:layout_scrollflags="scroll"
  app:contentscrim="#000000"
  android:layout_width="match_parent"
  android:layout_height="220dp">

  <textview
  android:text="banner区域"
  android:gravity="center"
  android:textcolor="#ffffff"
  android:background="#987545"
  android:layout_width="match_parent"
  android:layout_height="220dp"/>

 </android.support.design.widget.collapsingtoolbarlayout>

 <textview
  android:gravity="center"
  android:layout_width="match_parent"
  android:layout_height="30dp"
  android:text="悬浮的部分"/>

 </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="wrap_content"
  android:layout_height="wrap_content"
  android:layout_margin="@dimen/text_margin"
  android:text="@string/large_text"/>

 </android.support.v4.widget.nestedscrollview>

</android.support.design.widget.coordinatorlayout>

实现步骤:

1、将需要悬浮的layout放到collapsingtoolbarlayout之外,appbarlayout之内

2、将collapsingtoolbarlayoutapp:layout_scrollflags设置为scroll

3、给滚动的nestedscroolview设置

      app:layout_behavior="@string/appbar_scrolling_view_behavior"

就大功告成了(记得根布局要是coordinatorlayout)

最终效果:

总结

以上就是关于android滑动到顶部悬停效果的全部内容,大家都学会了吗?希望这篇文章对大家的学习或者工作带来一定的帮助,如果有疑问大家可以留言交流。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网