先看一下效果图:
<?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
相关文章:
,巨量百应是干嘛的?
如何在云主机上快速搭建网站?
盐城做公司网站,江苏电子版退休证办理流程?
广东专业制作网站有哪些,广东省能源集团有限公司官网?
jQuery 常见小例汇总
如何在IIS7中新建站点?详细步骤解析
广州网站设计制作一条龙,广州巨网网络科技有限公司是干什么的?
定制建站模板如何实现SEO优化与智能系统配置?18字教程
建站为何优先选择香港服务器?
建站主机是否等同于虚拟主机?
在线教育网站制作平台,山西立德教育官网?
实现虚拟支付需哪些建站技术支撑?
如何在云主机上快速搭建多站点网站?
潍坊网站制作公司有哪些,潍坊哪家招聘网站好?
制作网站怎么制作,*游戏网站怎么搭建?
c++如何打印函数堆栈信息_c++ backtrace函数与符号名解析【方法】
建站168自助建站系统:快速模板定制与SEO优化指南
企业微网站怎么做,公司网站和公众号有什么区别?
如何在IIS中新建站点并解决端口绑定冲突?
小型网站建站如何选择虚拟主机?
微信h5制作网站有哪些,免费微信H5页面制作工具?
,怎么用自己头像做动态表情包?
电商网站制作价格怎么算,网上拍卖流程以及规则?
*服务器网站为何频现安全漏洞?
香港服务器网站搭建教程-电商部署、配置优化与安全稳定指南
如何高效搭建专业期货交易平台网站?
实例解析Array和String方法
如何通过多用户协作模板快速搭建高效企业网站?
Bpmn 2.0的XML文件怎么画流程图
建站之星如何通过成品分离优化网站效率?
专业的网站制作设计是什么,如何制作一个企业网站,建设网站的基本步骤有哪些?
建站之星IIS配置教程:代码生成技巧与站点搭建指南
家庭建站与云服务器建站,如何选择更优?
移民网站制作流程,怎么看加拿大移民官网?
建站之星北京办公室:智能建站系统与小程序生成方案解析
高防服务器如何保障网站安全无虞?
网站制作免费,什么网站能看正片电影?
如何快速生成凡客建站的专业级图册?
导航网站建站方案与优化指南:一站式高效搭建技巧解析
网页设计与网站制作内容,怎样注册网站?
外汇网站制作流程,如何在工商银行网站上做外汇买卖?
如何通过FTP空间快速搭建安全高效网站?
平台云上自助建站如何快速打造专业网站?
怀化网站制作公司,怀化新生儿上户网上办理流程?
网站制作和推广的区别,想自己建立一个网站做推广,有什么快捷方法马上做好一个网站?
沈阳个人网站制作公司,哪个网站能考到沈阳事业编招聘的信息?
小自动建站系统:AI智能生成+拖拽模板,多端适配一键搭建
专业商城网站制作公司有哪些,pi商城官网是哪个?
如何用美橙互联一键搭建多站合一网站?
如何在Golang中使用replace替换模块_指定本地或远程路径
*请认真填写需求信息,我们会在24小时内与您取得联系。