先看一下效果图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hankkin.gradationtitlebar.QQSpeakActivity">
<com.hankkin.gradationscroll.GradationScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_banner"
android:scaleType="fitXY"
android:src="@drawable/banner3"
android:layout_width="match_parent"
android:layout_height="200dp" />
<com.hankkin.gradationscroll.NoScrollListview
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.hankkin.gradationscroll.NoScrollListview>
</LinearLayout>
</com.hankkin.gradationscroll.GradationScrollView>
<TextView
android:paddingBottom="10dp"
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center|bottom"
android:text="我是标题"
android:textSize="18sp"
android:textColor="@color/transparent"
android:background="#00000000" />
</RelativeLayout>
public class GradationScrollView extends ScrollView {
public interface ScrollViewListener {
void onScrollChanged(GradationScrollView scrollView, int x, int y,
int oldx, int oldy);
}
private ScrollViewListener scrollViewListener = null;
public GradationScrollView(Context context) {
super(context);
}
public GradationScrollView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public GradationScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollViewListener(ScrollViewListener scrollViewListener) {
this.scrollViewListener = scrollViewListener;
}
@Override
protected void onScrollChanged(int x, int y, int oldx, int oldy) {
super.onScrollChanged(x, y, oldx, oldy);
if (scrollViewListener != null) {
scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
}
}
}
我们需要获取图片的高度,并且设置滚动监听,随着滚动的距离来设置标题栏的颜色透明度和字体颜色的透明度
/**
* 获取顶部图片高度后,设置滚动监听
*/
private void initListeners() {
ViewTreeObserver vto = ivBanner.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
textView.getViewTreeObserver().removeGlobalOnLayoutListener(
this);
height = ivBanner.getHeight();
scrollView.setScrollViewListener(QQSpeakActivity.this);
}
});
}
/**
* 滑动监听
* @param scrollView
* @param x
* @param y
* @param oldx
* @param oldy
*/
@Override
public void onScrollChanged(GradationScrollView scrollView, int x, int y,
int oldx, int oldy) {
// TODO Auto-generated method stub
if (y <= 0) { //设置标题的背景颜色
textView.setBackgroundColor(Color.argb((int) 0, 144,151,166));
} else if (y > 0 && y <= height) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变
float scale = (float) y / height;
float alpha = (255 * scale);
textView.setTextColor(Color.argb((int) alpha, 255,255,255));
textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166));
} else { //滑动到banner下面设置普通颜色
textView.setBackgroundColor(Color.argb((int) 255, 144,151,166));
}
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
# android
# 标题栏渐变
# Android ScrollView滑动实现仿QQ空间标题栏渐变
# Android仿淘宝商品拖动查看详情及标题栏渐变功能
# Android中实现监听ScrollView滑动事件
# android TextView不用ScrollViewe也可以滚动的方法
# 在android中ScrollView嵌套ScrollView解决方案
# android 实现ScrollView自动滚动的实例代码
# android 自定义ScrollView实现背景图片伸缩的实现代码及思路
# android开发教程之文本框加滚动条scrollview
# Android之scrollview滑动使标题栏渐变背景色的实例代码
# 我是
# 先看
# 标题栏
# ImageView
# vertical
# orientation
# iv_banner
# src
# fitXY
# scaleType
# id
# GradationScrollView
# gradationscroll
# scrollview
# wrap_content
# LinearLayout
# scrollbars
# drawable
# textview
# gravity
相关文章:
济南网站制作的价格,历城一职专官方网站?
b2c电商网站制作流程,b2c水平综合的电商平台?
建站之星如何防范黑客攻击与数据泄露?
营销式网站制作方案,销售哪个网站招聘效果最好?
临沂网站制作公司有哪些,临沂第四中学官网?
车管所网站制作流程,交警当场开简易程序处罚决定书,在交警网站查询不到怎么办?
活动邀请函制作网站有哪些,活动邀请函文案?
如何在景安服务器上快速搭建个人网站?
如何使用Golang table-driven基准测试_多组数据测量函数效率
如何获取开源自助建站系统免费下载链接?
建站之星收费标准详解:套餐费用及年费价格表一览
宝塔新建站点为何无法访问?如何排查?
广州建站公司哪家好?十大优质服务商推荐
建站之星CMS五站合一模板配置与SEO优化指南
如何选择长沙网站建站模板?H5响应式与品牌定制哪个更优?
如何在阿里云虚拟机上搭建网站?步骤解析与避坑指南
高性能网站服务器部署指南:稳定运行与安全配置优化方案
广州网站建站公司选择指南:建站流程与SEO优化关键词解析
建站之星如何助力网站排名飙升?揭秘高效技巧
浅析上传头像示例及其注意事项
北京网站制作的公司有哪些,北京白云观官方网站?
简单实现Android验证码
如何选择美橙互联多站合一建站方案?
图册素材网站设计制作软件,图册的导出方式有几种?
宝塔建站无法访问?如何排查配置与端口问题?
如何在阿里云ECS服务器部署织梦CMS网站?
如何通过IIS搭建网站并配置访问权限?
香港服务器网站测试全流程:性能评估、SEO加载与移动适配优化
制作无缝贴图网站有哪些,3dmax无缝贴图怎么调?
如何用低价快速搭建高质量网站?
儿童网站界面设计图片,中国少年儿童教育网站-怎么去注册?
如何选择高效便捷的WAP商城建站系统?
如何快速搭建高效WAP手机网站?
寿县云建站:智能SEO优化与多行业模板快速上线指南
制作假网页,招聘网的薪资待遇,会有靠谱的吗?一面试又各种折扣?
制作网站哪家好,cc、.co、.cm哪个域名更适合做网站?
nginx修改上传文件大小限制的方法
如何彻底删除建站之星生成的Banner?
七夕网站制作视频,七夕大促活动怎么报名?
如何在建站之星绑定自定义域名?
如何快速使用云服务器搭建个人网站?
广州网站制作公司哪家好一点,广州欧莱雅百库网络科技有限公司官网?
Python lxml的etree和ElementTree有什么区别
定制建站哪家更专业可靠?推荐榜单揭晓
建站之星如何通过成品分离优化网站效率?
中山网站制作网页,中山新生登记系统登记流程?
企业在线网站设计制作流程,想建设一个属于自己的企业网站,该如何去做?
教学论文网站制作软件有哪些,写论文用什么软件
?
建站之星如何取消后台验证码生成?
香港服务器如何优化才能显著提升网站加载速度?
*请认真填写需求信息,我们会在24小时内与您取得联系。