项目中有一个这样的要求 一个页面是要求嵌套在ScrollView中 比如某公司的详情页面
刚刚打开时顶部标题显示公司详情。当上拉到一定程度即公司职位已经滑出屏幕。此时顶部标题显示职位详情
代码说明
由于 ScrollView 只提供了一个这样的监听方法
protected void onScrollChanged(int x, int y, int oldx, int oldy)
显然这个方法是不能被外界调用的,因此就需要把它暴露出去。
自定义接口
public interface SwitchScrollViewListener {
void onScrollChanged(SwitchScrollView scrollView, int x, int y, int oldx, int oldy);
}
Activity布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/activity_switchscrollview_titletextview"
android:layout_width="match_parent"
android:layout_height="70dp"
android:gravity="center"
android:textColor="#FFFFFF"
android:background="@color/colorPrimary"
android:text="职位详情"/>
<com.wjn.myview.view.SwitchScrollView
android:id="@+id/activity_switchscrollview_switchscrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/activity_switchscrollview_contexttextview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="10dp"
android:text=""/>
</LinearLayout>
</com.wjn.myview.view.SwitchScrollView>
</LinearLayout>
效果