之前也出个微博悬停效果,但是它里面是底部是viewpager的,还有它的自定义控件过于复杂。
这次写一个底部就一个recyclerview,算是改良版本。
废话先来看下效果图,是不是你们要的。由于我找不到csdn博客上上传视频的地方,只能上传效果。
第一张:首屏画面
第二张:滑动画面
第三张:滑动留言精选处悬停效果
希望大家能看懂三张图,联想到其中的操作,第三张图的发表感想按钮是显示隐藏弄出来了的,它和留言精选同在一个父控件中的。
这个应该是处理事件分发应用的最好体现了,能自己搞出来的,事件分发就过关了。不过我也是在别人的基础上改的,嘿嘿。
核心代码:LetterStickyNavLayout
public class LetterStickyNavLayout extends LinearLayout {
private ScrollListener scrollListener;
private Context mContext;
private View mTop;
private View mNav;
//private ViewPager mViewPager;
//private SwipeRefRecyclerView mSRRceylerView;
private LinearLayout llContent;
private int mTopViewHeight;
private ViewGroup mInnerScrollView;
private boolean isTopHidden = false;
private OverScroller mScroller;
private VelocityTracker mVelocityTracker;
private int mTouchSlop;
private int mMaximumVelocity, mMinimumVelocity;
private float mLastY;
private boolean mDragging;
private boolean isInControl = false;
private boolean isChange=false;
private int screenWidth;
public LetterStickyNavLayout(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(LinearLayout.VERTICAL);
mContext = context;
mScroller = new OverScroller(context);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mMaximumVelocity = ViewConfiguration.get(context)
.getScaledMaximumFlingVelocity();
mMinimumVelocity = ViewConfiguration.get(context)
.getScaledMinimumFlingVelocity();
screenWidth=Utils.getScreenWidthPx(mContext);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mTop = findViewById(R.id.id_stickynavlayout_topview);
mNav = findViewById(R.id.id_stickynavlayout_indicator);
//View sfrView = findViewById(R.id.id_stickynavlayout_swiperefrecyclerview);
View llView = findViewById(R.id.id_stickynavlayout_content);
if (!(llView instanceof LinearLayout)) {
throw new RuntimeException(
"id_stickynavlayout_content show used by LinearLayout !");
}
// if (!(sfrView instanceof SwipeRefRecyclerView)) {
// throw new RuntimeException(
// "SwipeRefRecyclerView show used by SwipeRefRecyclerView !");
// }
//
// mSRRceylerView = (SwipeRefRecyclerView) sfrView;
llContent =(LinearLayout)llView;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
ViewGroup.LayoutParams params;
// if(mSRRceylerView != null && mSRRceylerView.getVisibility() == VISIBLE){
// params = mSRRceylerView.getLayoutParams();
// }else{
// params = llContent.getLayoutParams();
// }
params = llContent.getLayoutParams();
int height;
if(Utils.checkDeviceHasNavigationBar(mContext)){
height = getMeasuredHeight() - mNav.getMeasuredHeight() + Utils.dip2px(mContext, 34);
}else{
height = getMeasuredHeight() - mNav.getMeasuredHeight();
}
//int height = getMeasuredHeight() - mNav.getMeasuredHeight();
if (height >= screenWidth && !isChange) {
params.height = height;
isChange = true;
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mTopViewHeight = mTop.getMeasuredHeight() ;
LogUtils.i("mTopViewHeight",mTopViewHeight+"");
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int action = ev.getAction();
float y = ev.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
mLastY = y;
break;
case MotionEvent.ACTION_MOVE:
float dy = y - mLastY;
getCurrentScrollView();
if(mInnerScrollView != null && mInnerScrollView.getVisibility()== View.VISIBLE && mInnerScrollView instanceof SwipeRefRecyclerView){
LogUtils.i("swi","exist");
SwipeRefRecyclerView mSRRceylerView = (SwipeRefRecyclerView) mInnerScrollView;
Recyc