<?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.znke.pulltorefresh_top.MainActivity">
<!--<com.znke.pulltorefresh_top.tool.ToTopScrollView .../>-->
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_top"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="111111111111"
android:textSize="20sp" />
...........
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#AAAAAA" />
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:text="12000000000000"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
<com.znke.pulltorefresh_top.tool.ToTopImageView
android:id="@+id/imageView_to_top"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/to_top" />
</RelativeLayout>
mScrollView.setOnScrollChangeListener();
public class ToTopScrollView extends ScrollView {
private OnMyScrollListener onMyScrollListener;
public void setOnMyScrollListener(OnMyScrollListener onMyScrollListener) {
this.onMyScrollListener = onMyScrollListener;
}
...
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if(onMyScrollListener != null)
onMyScrollListener.onScrollChanged(l,t,oldl,oldt);
}
public interface OnMyScrollListener{
void onScrollChanged(int x, int y, int oldx, int oldy);
}
}
mScrollView.setOnTouchListener()
@Override
protected ScrollView createRefreshableView(Context context, AttributeSet attrs) {
ScrollView scrollView;
if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) {
scrollView = new InternalScrollViewSDK9(context, attrs);
} else {
scrollView = new ScrollView(context, attrs);
}
scrollView.setId(R.id.scrollview);
return scrollView;
}
final ScrollView scrollView = mScrollView.getRefreshableView();
/**
* 获取待监控的view对象
* 实时调起线程,监控是否scroll停止,来判断是否需要显示imageView
* @param targetView 需要监控的对象
*/
public void tellMe(View targetView) {
if (targetView == null)
throw new IllegalArgumentException("please set targetView who to scrollTo");
if (this.targetView == null)
this.targetView = targetView;
if (!isStarting) {
new Thread(scanThread).start();
}
}
private class MyCallback implements Runnable {
@Override
public void run() {
/**
* 获取实时的卷动值,不要传递scroll值给我
*/
endScrollX = targetView.getScrollX();
int scrollY = targetView.getScrollY();
if (endScrollY != scrollY) {
endScrollY = scrollY;
} else {
if (endScrollY >= limitHeight) {
if (!thisStateVisible)
visible();
} else {
if (thisStateVisible)
gone();
}
/**
* 已判定,卷动停止,显示或隐藏当前view已完成
* 退出监控scroll线程
*/
clearCallBacks();
}
}
}
private PullToRefreshScrollView mScrollView;
private ToTopImageView imageView_to_top;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pull_to_refresh_scroll_view);
imageView_to_top = (ToTopImageView) findViewById(R.id.imageView_to_top);
imageView_to_top.setLimitHeight(800);
mScrollView = (PullToRefreshScrollView) findViewById(R.id.scrollView);
final ScrollView scrollView = mScrollView.getRefreshableView();
//mScrollView.setOnTouchListener(); 无效
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_MOVE:
imageView_to_top.tellMe(scrollView);
break;
}
return false;
}
});
}
@Override
protected void onDestroy() {
imageView_to_top.clearCallBacks();
super.onDestroy();
}
<com.znke.pulltorefresh_top.tool.ToTopImageView android:id="@+id/imageView_to_top" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="5dp" android:layout_marginRight="5dp" android:background="@drawable/to_top" />
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有