<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="www.sf.com.searchframe.MainActivity"> <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" /> <!--搜索框--> <LinearLayout android:id="@+id/ll_search" android:layout_width="match_parent" android:layout_height="50dp" android:background="#00ab95" android:orientation="horizontal"> ...... </LinearLayout> </RelativeLayout>
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
//监听滑动状态的改变
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
//用于监听ListView屏幕滚动
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int[] ints = new int[2];
mImage.getLocationOnScreen(ints);
/**
* mImage距离屏幕顶部的距离(图片顶部在屏幕最上面,向上滑动为负数,所以取反)
* 如果不隐藏状态栏,需要加上状态栏的高度;隐藏状态栏就不用加了;
*/
int scrollY = -ints[1]+statusHeight;
//mImage这个view的高度
int imageHeight = mImage.getHeight();
if (mImage != null && imageHeight > 0) {
//如果“图片”没有向上滑动,设置为全透明
if (scrollY < 0) {
llSearch.getBackground().setAlpha(0);
} else {
//“图片”已经滑动,而且还没有全部滑出屏幕,根据滑出高度的比例设置透明度的比例
if (scrollY < imageHeight) {
int progress = (int) (new Float(scrollY) / new Float(imageHeight) * 255);//255
llSearch.getBackground().setAlpha(progress);
} else {
//“图片”全部滑出屏幕的时候,设为完全不透明
llSearch.getBackground().setAlpha(255);
}
}
}
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有