/**
* 实现左右两个ListView共同滑动,并且保持第一个ListView锁定
*
*/
public class TwoListViewLayout extends RelativeLayout {
private LinearLayout mLeft, mRight;
private RelativeLayout mLeftHeader, mRightheader;
private SynchScrollListView mlvLeft, mlvRight;
private HorizontalScrollView mScroll;
public TwoListViewLayout(Context context) {
super(context);
init(context, null);
}
public TwoListViewLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public TwoListViewLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
/**
* 初始化
*
* @param context
*/
private void init(Context context, AttributeSet attrs) {
final LayoutInflater li = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.two_listview, this);
mLeft = (LinearLayout) findViewById(R.id.left);
mRight = (LinearLayout) findViewById(R.id.right);
mLeftHeader = (RelativeLayout) findViewById(R.id.left_header);
mRightheader = (RelativeLayout) findViewById(R.id.right_header);
mlvLeft = (SynchScrollListView) findViewById(R.id.left_listview);
mlvRight = (SynchScrollListView) findViewById(R.id.right_listview);
mScroll = (HorizontalScrollView) findViewById(R.id.right_scrollview);
if (attrs != null) {
final TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.listView, 0, 0);
final LinearLayout.LayoutParams leftP = new LinearLayout.LayoutParams(
a.getLayoutDimension(R.styleable.listView_leftWidth,
"leftWidth"),// (R.styleable.listView_leftWidth,
// ViewGroup.LayoutParams.WRAP_CONTENT),
a.getLayoutDimension(R.styleable.listView_leftHeight,
"leftHeight"));// a.getDimensionPixelSize(R.styleable.listView_leftHeight,
// ViewGroup.LayoutParams.WRAP_CONTENT));
mlvLeft.setLayoutParams(leftP);
final LinearLayout.LayoutParams rightP = new LinearLayout.LayoutParams(
a.getLayoutDimension(R.styleable.listView_rightWidth,
"rightWidth"),// a.getDimensionPixelSize(R.styleable.listView_rightWidth,
// ViewGroup.LayoutParams.WRAP_CONTENT),
a.getLayoutDimension(R.styleable.listView_rightHeight,
"rightHeight"));// a.getDimensionPixelSize(R.styleable.listView_rightHeight,
// ViewGroup.LayoutParams.WRAP_CONTENT));
mlvRight.setLayoutParams(rightP);
a.recycle();
}
}
/**
* 获得左列表的表头
*
* @return a View is left table header
*/
public View getLeftHeader() {
return mLeftHeader.getChildAt(0);
}
/**
* 添加左列表的表头
*
* @param header
*/
public void setLeftHeader(View header) {
mLeftHeader.removeAllViews();
mLeftHeader.addView(header);
requestLayout();
}
public void setLeftHeader(View header, ViewGroup.LayoutParams lp) {
mLeftHeader.removeAllViews();
mLeftHeader.addView(header, lp);
requestLayout();
}
/**
* 获得右列表的表头
*
* @return a View is left table header
*/
public View getRightHeader() {
return mRightheader.getChildAt(0);
}
/**
* 添加右列表的表头
*
* @param header
*/
public void setRightHeader(View header) {
mRightheader.removeAllViews();
mRightheader.addView(header);
requestLayout();
}
public void setRightHeader(View header, ViewGroup.LayoutParams lp) {
mRightheader.removeAllViews();
mRightheader.addView(header, lp);
requestLayout();
}
/**
* 获得左列表
*
* @return
*/
public ListView getLeftListView() {
return mlvLeft;
}
/**
* 获得右列表
*
* @return
*/
public ListView getRightListView() {
return mlvRight;
}
/**
* 双列表联动, 使两列表实现同步滑动
*/
public void linkage() {
mlvLeft.linkListView(mlvRight);
mlvRight.linkListView(mlvLeft);
}
}
* 实现左右两个ListView共同滑动,并且保持第一个ListView锁定
*
*/
public class TwoListViewLayout extends RelativeLayout {
private LinearLayout mLeft, mRight;
private RelativeLayout mLeftHeader, mRightheader;
private SynchScrollListView mlvLeft, mlvRight;
private HorizontalScrollView mScroll;
public TwoListViewLayout(Context context) {
super(context);
init(context, null);
}
public TwoListViewLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public TwoListViewLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
/**
* 初始化
*
* @param context
*/
private void init(Context context, AttributeSet attrs) {
final LayoutInflater li = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.two_listview, this);
mLeft = (LinearLayout) findViewById(R.id.left);
mRight = (LinearLayout) findViewById(R.id.right);
mLeftHeader = (RelativeLayout) findViewById(R.id.left_header);
mRightheader = (RelativeLayout) findViewById(R.id.right_header);
mlvLeft = (SynchScrollListView) findViewById(R.id.left_listview);
mlvRight = (SynchScrollListView) findViewById(R.id.right_listview);
mScroll = (HorizontalScrollView) findViewById(R.id.right_scrollview);
if (attrs != null) {
final TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.listView, 0, 0);
final LinearLayout.LayoutParams leftP = new LinearLayout.LayoutParams(
a.getLayoutDimension(R.styleable.listView_leftWidth,
"leftWidth"),// (R.styleable.listView_leftWidth,
// ViewGroup.LayoutParams.WRAP_CONTENT),
a.getLayoutDimension(R.styleable.listView_leftHeight,
"leftHeight"));// a.getDimensionPixelSize(R.styleable.listView_leftHeight,
// ViewGroup.LayoutParams.WRAP_CONTENT));
mlvLeft.setLayoutParams(leftP);
final LinearLayout.LayoutParams rightP = new LinearLayout.LayoutParams(
a.getLayoutDimension(R.styleable.listView_rightWidth,
"rightWidth"),// a.getDimensionPixelSize(R.styleable.listView_rightWidth,
// ViewGroup.LayoutParams.WRAP_CONTENT),
a.getLayoutDimension(R.styleable.listView_rightHeight,
"rightHeight"));// a.getDimensionPixelSize(R.styleable.listView_rightHeight,
// ViewGroup.LayoutParams.WRAP_CONTENT));
mlvRight.setLayoutParams(rightP);
a.recycle();
}
}
/**
* 获得左列表的表头
*
* @return a View is left table header
*/
public View getLeftHeader() {
return mLeftHeader.getChildAt(0);
}
/**
* 添加左列表的表头
*
* @param header
*/
public void setLeftHeader(View header) {
mLeftHeader.removeAllViews();
mLeftHeader.addView(header);
requestLayout();
}
public void setLeftHeader(View header, ViewGroup.LayoutParams lp) {
mLeftHeader.removeAllViews();
mLeftHeader.addView(header, lp);
requestLayout();
}
/**
* 获得右列表的表头
*
* @return a View is left table header
*/
public View getRightHeader() {
return mRightheader.getChildAt(0);
}
/**
* 添加右列表的表头
*
* @param header
*/
public void setRightHeader(View header) {
mRightheader.removeAllViews();
mRightheader.addView(header);
requestLayout();
}
public void setRightHeader(View header, ViewGroup.LayoutParams lp) {
mRightheader.removeAllViews();
mRightheader.addView(header, lp);
requestLayout();
}
/**
* 获得左列表
*
* @return
*/
public ListView getLeftListView() {
return mlvLeft;
}
/**
* 获得右列表
*
* @return
*/
public ListView getRightListView() {
return mlvRight;
}
/**
* 双列表联动, 使两列表实现同步滑动
*/
public void linkage() {
mlvLeft.linkListView(mlvRight);
mlvRight.linkListView(mlvLeft);
}
}