解析滚动视图——仿QQ空间标题栏渐变

  

先看一下效果图:

  

解析滚动视图——仿QQ空间标题栏渐变

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:工具=" http://schemas.android.com/tools "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   工具:上下文=癱om.hankkin.gradationtitlebar.QQSpeakActivity”比;      & lt; com.hankkin.gradationscroll.GradationScrollView   android: id=癅 + id/滚动视图”   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android:滚动条="没有"比;   LinearLayout & lt;   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   面向android:=按怪薄北?   & lt; ImageView   android: id=癅 + id/iv_banner”   android: scaleType=" fitXY "   android: src=" https://www.yisu.com/zixun/@drawable banner3 "   android: layout_width=" match_parent "   android: layout_height=" 200 dp/比;   & lt; com.hankkin.gradationscroll.NoScrollListview   android: id=癅 + id/视图”   android: layout_width=" match_parent "   android: layout_height=皐rap_content”比;   & lt;/com.hankkin.gradationscroll.NoScrollListview>   & lt;/LinearLayout>   & lt;/com.hankkin.gradationscroll.GradationScrollView>   & lt; TextView   android: paddingBottom=" 10 dp”   android: id=癅 + id/textview”   android: layout_width=" match_parent "   android: layout_height=" 55 dp "   android:重力="中心|底”   android:文本="我是标题”   android: textSize=" 18 sp "   android:输入textColor=" @color/透明”   android:背景=" # 00000000 "/比;   & lt;/RelativeLayout>            公开课GradationScrollView延伸ScrollView {      公共接口ScrollViewListener {   空白>/* *   *获取顶部图片高度后,设置滚动监听   */私人空间initListeners () {   ViewTreeObserver vto=ivBanner.getViewTreeObserver ();   vto。addOnGlobalLayoutListener(新ViewTreeObserver.OnGlobalLayoutListener () {   @Override   公共空间onGlobalLayout () {   textView.getViewTreeObserver () .removeGlobalOnLayoutListener (   这个);   身高=ivBanner.getHeight ();      scrollView.setScrollViewListener (QQSpeakActivity.this);   }   });   }/* *   *滑动监听   * @param滚动视图   * @param x   * @param y   * @param oldx   * @param老人   */@Override   公共空间onScrollChanged (GradationScrollView滚动视图,int x, int y,   int oldx int老人){//TODO自动生成方法存根   如果(y & lt;=0){//设置标题的背景颜色   textView.setBackgroundColor (Color.argb ((int) 0, 144151166));   }else if (y比;0,,y & lt;=身高){//滑动距离小于横幅图的高度时,设置背景和字体颜色颜色透明度渐变   浮动比例=(浮动)y/高;   浮动α=(255 *规模);   textView.setTextColor (Color.argb ((int)α,255255255));   textView.setBackgroundColor (Color.argb ((int)α,144151166));   其他}{//滑动到旗帜下面设置普通颜色   textView.setBackgroundColor (Color.argb ((int) 255, 144151166));   }   }      

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!

解析滚动视图——仿QQ空间标题栏渐变