因项目中需要实现表格类的显示方式,显示数量不确定,同时产品对一些体验,以及设计的要求,参考网上资料,自己写的一个双向滑动listview,废话不多说直接上代码和效果图
1.效果图
2代码:
首先,界面说明(其他东西可忽略项目中需要使用),竖向是一个listview,横向是一个自定义HorizontalScrollView,(此处没有使用自定义横向listview,因为时间紧,并且事件触摸分发繁琐,就索性直接一个自定义HorizontalScrollView)代码如下:
CustomScrollView 类:
package view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;
import fragment.PlanScheduleFragment;
public class CustomScrollView extends HorizontalScrollView{
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// activity = (MainActivity) context;
}
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// activity = (MainActivity) context;
}
public CustomScrollView(Context context) {
super(context);
// activity = (MainActivity) context;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
//PlanScheduleFragment的实例,当前的mTouchView 是CustomScrollView的实例,滑动进行触摸赋值
PlanScheduleFragment.planScheduleFragment.mTouchView = this;
return super.onTouchEvent(ev);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
//当前的CHSCrollView被触摸时,滑动其它
if (PlanScheduleFragment.planScheduleFragment.mTouchView == this) {
PlanScheduleFragment.planScheduleFragment.onScrollChanged(l, t, oldl, oldt);
} else {
super.onScrollChanged(l, t, oldl, oldt);
}
}
}
PlanScheduleFragment类:
package fragment;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import utils.ScheduleManagerUtil;
import view.CustomScrollView;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.wi