Skip to content

Commit

Permalink
README.md
Browse files Browse the repository at this point in the history
README.md
  • Loading branch information
RmondJone committed Mar 15, 2018
1 parent 5413b0b commit 582eefe
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 44 deletions.
4 changes: 2 additions & 2 deletions LockTableViewProject/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
// compile project(':locktableview')
compile 'com.github.RmondJone:LockTableView:1.0.9'
compile project(':locktableview')
// compile 'com.github.RmondJone:LockTableView:1.0.9'
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setLockFristRow(true) //是否锁定第一行
.setMaxColumnWidth(100) //列最大宽度
.setMinColumnWidth(60) //列最小宽度
.setColumnWidth(1,60) //设置指定列文本宽度
.setMinRowHeight(20)//行最小高度
.setMaxRowHeight(60)//行最大高度
.setTextViewSize(16) //单元格字体大小
Expand All @@ -68,12 +69,12 @@ public void onTableViewScrollChange(int x, int y) {
.setTableViewRangeListener(new LockTableView.OnTableViewRangeListener() {
@Override
public void onLeft(HorizontalScrollView view) {
// Log.e("滚动边界","滚动到最左边");
Log.e("滚动边界","滚动到最左边");
}

@Override
public void onRight(HorizontalScrollView view) {
// Log.e("滚动边界","滚动到最右边");
Log.e("滚动边界","滚动到最右边");
}
})//设置横向滚动边界监听
.setOnLoadingListener(new LockTableView.OnLoadingListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.method.NumberKeyListener;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
Expand Down Expand Up @@ -183,6 +184,14 @@ public class LockTableView {
* 列表适配器
*/
private TableViewAdapter mTableViewAdapter;
/**
* 指定要改变列数
*/
private int mColumnNum = -1;
/**
* 指定要改变的列宽度(dp)
*/
private int mColumnWidth = -1;


/**
Expand Down Expand Up @@ -294,6 +303,10 @@ private void initData() {
}
// Log.e("第"+i+"行列最大宽度",buffer.toString());
}
//如果用户指定某列宽度则按照用户指定宽度算
if (mColumnNum >= 0 && mColumnWidth > 0) {
changeColumnWidth(mColumnNum, mColumnWidth);
}
// Log.e("每列最大宽度dp:",mColumnMaxWidths.toString());


Expand All @@ -313,7 +326,13 @@ private void initData() {
int maxHeight = measureTextHeight(textView, rowDatas.get(0));
mRowMaxHeights.add(maxHeight);
for (int j = 0; j < rowDatas.size(); j++) {
int currentHeight = measureTextHeight(textView, rowDatas.get(j));
int currentHeight;
//如果用户指定某列宽度则按照用户指定宽度算对应列的高度
if (j == mColumnNum && mColumnWidth > 0) {
currentHeight = getTextViewHeight(textView, rowDatas.get(j), mColumnWidth);
} else {
currentHeight = measureTextHeight(textView, rowDatas.get(j));
}
buffer.append("[" + currentHeight + "]");
if (currentHeight > maxHeight) {
mRowMaxHeights.set(i, currentHeight);
Expand Down Expand Up @@ -412,28 +431,28 @@ public void onTableViewScrollChange(int x, int y) {
changeAllScrollView(x, y);
}
});
if(mOnItemClickListenter!=null){
if (mOnItemClickListenter != null) {
mTableViewAdapter.setOnItemClickListenter(mOnItemClickListenter);
}
if(mOnItemLongClickListenter!=null){
if (mOnItemLongClickListenter != null) {
mTableViewAdapter.setOnItemLongClickListenter(mOnItemLongClickListenter);
}
if(mOnItemSeletor!=0){
if (mOnItemSeletor != 0) {
mTableViewAdapter.setOnItemSeletor(mOnItemSeletor);
}else{
} else {
mTableViewAdapter.setOnItemSeletor(R.color.dashline_color);
}
mTableViewAdapter.setTableViewRangeListener(new OnTableViewRangeListener() {
@Override
public void onLeft(HorizontalScrollView view) {
if (mTableViewRangeListener!=null){
mTableViewRangeListener.onLeft(view);
}
if (mTableViewRangeListener != null) {
mTableViewRangeListener.onLeft(view);
}
}

@Override
public void onRight(HorizontalScrollView view) {
if (mTableViewRangeListener!=null){
if (mTableViewRangeListener != null) {
mTableViewRangeListener.onRight(view);
}
}
Expand Down Expand Up @@ -487,14 +506,14 @@ public void onScrollChanged(HorizontalScrollView scrollView, int x, int y) {

@Override
public void onScrollFarLeft(HorizontalScrollView scrollView) {
if(mTableViewRangeListener!=null){
if (mTableViewRangeListener != null) {
mTableViewRangeListener.onLeft(scrollView);
}
}

@Override
public void onScrollFarRight(HorizontalScrollView scrollView) {
if(mTableViewRangeListener!=null){
if (mTableViewRangeListener != null) {
mTableViewRangeListener.onRight(scrollView);
}
}
Expand All @@ -510,14 +529,14 @@ public void onScrollChanged(HorizontalScrollView scrollView, int x, int y) {

@Override
public void onScrollFarLeft(HorizontalScrollView scrollView) {
if(mTableViewRangeListener!=null){
if (mTableViewRangeListener != null) {
mTableViewRangeListener.onLeft(scrollView);
}
}

@Override
public void onScrollFarRight(HorizontalScrollView scrollView) {
if(mTableViewRangeListener!=null){
if (mTableViewRangeListener != null) {
mTableViewRangeListener.onRight(scrollView);
}
}
Expand Down Expand Up @@ -608,6 +627,26 @@ private int getTextViewHeight(TextView textView, String text) {
return 0;
}

/**
* 说明 根据文字和指定宽度计算高度
* 作者 郭翰林
* 创建时间 2018/3/15 下午12:39
*
* @param textView
* @param text
* @param width
* @return
*/
private int getTextViewHeight(TextView textView, String text, int width) {
if (textView != null) {
TextPaint textPaint = textView.getPaint();
StaticLayout staticLayout = new StaticLayout(text, textPaint, DisplayUtil.dip2px(mContext, width), Layout.Alignment.ALIGN_NORMAL, 1, 0, false);
int height = DisplayUtil.px2dip(mContext, staticLayout.getHeight());
return height;
}
return 0;
}

/**
* 根据文字计算textview的高度
*
Expand Down Expand Up @@ -679,6 +718,24 @@ private void createScollview(HorizontalScrollView scrollView, List<String> datas
scrollView.addView(linearLayout);
}

/**
* 说明 改变指定列指定宽度
* 作者 郭翰林
* 创建时间 2018/3/15 上午11:06
*
* @param mColumnNum
* @param mColumnWidth
*/
private void changeColumnWidth(int mColumnNum, int mColumnWidth) {
if (mColumnMaxWidths != null && mColumnMaxWidths.size() > 0) {
if (mColumnNum < mColumnMaxWidths.size() && mColumnNum >= 0) {
mColumnMaxWidths.set(mColumnNum, mColumnWidth + DisplayUtil.px2dip(mContext, 15) * 2);
} else {
Log.e("LockTableView", "指定列数不存在");
}
}
}


//属性设置
public LockTableView setLockFristRow(boolean lockFristRow) {
Expand Down Expand Up @@ -766,6 +823,19 @@ public LockTableView setOnItemSeletor(int mOnItemSeletor) {
return this;
}

/**
* 指定第几列对应的宽度
*
* @param mColumnNum
* @param mColumnWidth
* @return
*/
public LockTableView setColumnWidth(int mColumnNum, int mColumnWidth) {
this.mColumnNum = mColumnNum;
this.mColumnWidth = mColumnWidth;
return this;
}

//值获取
public ArrayList<Integer> getColumnMaxWidths() {
return mColumnMaxWidths;
Expand Down Expand Up @@ -809,6 +879,7 @@ public void setTableDatas(ArrayList<ArrayList<String>> mTableDatas) {
mTableViewAdapter.notifyDataSetChanged();
}


/**
* 横向滚动监听
*/
Expand All @@ -826,12 +897,13 @@ public interface OnTableViewListener {
/**
* 横向滚动视图滑动到边界的监听
*/
public interface OnTableViewRangeListener{
public interface OnTableViewRangeListener {

/**
* 说明 最左侧
* 作者 郭翰林
* 创建时间 2017/12/14 下午4:45
*
* @param view
*/
void onLeft(HorizontalScrollView view);
Expand All @@ -840,6 +912,7 @@ public interface OnTableViewRangeListener{
* 说明 最右侧
* 作者 郭翰林
* 创建时间 2017/12/14 下午4:45
*
* @param view
*/
void onRight(HorizontalScrollView view);
Expand Down Expand Up @@ -878,26 +951,26 @@ public interface OnLoadingListener {
* 作者 郭翰林
* 创建时间 2018/2/2 下午4:50
*/
public interface OnItemClickListenter{
public interface OnItemClickListenter {

/**
* @param item 点击项
* @param item 点击项
* @param position 点击位置
*/
void onItemClick(View item,int position);
void onItemClick(View item, int position);
}

/**
* 说明 Item长按事件
* 作者 郭翰林
* 创建时间 2018/2/2 下午4:50
*/
public interface OnItemLongClickListenter{
public interface OnItemLongClickListenter {

/**
* @param item 点击项
* @param item 点击项
* @param position 点击位置
*/
void onItemLongClick(View item,int position);
void onItemLongClick(View item, int position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,20 @@ public void onBindViewHolder(final TableViewHolder holder, int position) {
public void onItemSelected(View view, int position) {
RecyclerView.LayoutManager mLockLayoutManager = holder.mLockRecyclerView.getLayoutManager();
int itemCount=mLockLayoutManager.getItemCount();
View item=mLockLayoutManager.getChildAt(position+1);
View item=mLockLayoutManager.getChildAt(position);
item.setBackgroundColor(ContextCompat.getColor(mContext,mOnItemSeletor));
for(int i=0;i<itemCount;i++){
if(i!=position){
mLockLayoutManager.getChildAt(i+1).setBackgroundColor(Color.TRANSPARENT);
mLockLayoutManager.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
}
RecyclerView.LayoutManager mUnLockLayoutManager = holder.mMainRecyclerView.getLayoutManager();
int itemUnLockCount=mUnLockLayoutManager.getItemCount();
View mUnlockItem=mUnLockLayoutManager.getChildAt(position+1);
View mUnlockItem=mUnLockLayoutManager.getChildAt(position);
mUnlockItem.setBackgroundColor(ContextCompat.getColor(mContext,mOnItemSeletor));
for(int i=0;i<itemUnLockCount;i++){
if(i!=position){
mUnLockLayoutManager.getChildAt(i+1).setBackgroundColor(Color.TRANSPARENT);
mUnLockLayoutManager.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
}
}
Expand All @@ -183,8 +183,6 @@ public void onItemSelected(View view, int position) {
if (mOnItemLongClickListenter != null) {
mLockAdapter.setOnItemLongClickListenter(mOnItemLongClickListenter);
}
holder.mLockRecyclerView.setPullRefreshEnabled(false);
holder.mLockRecyclerView.setLoadingMoreEnabled(false);
holder.mLockRecyclerView.setLayoutManager(layoutManager);
holder.mLockRecyclerView.addItemDecoration(new DividerItemDecoration(mContext
, DividerItemDecoration.VERTICAL));
Expand All @@ -211,20 +209,20 @@ public void onItemSelected(View view, int position) {
public void onItemSelected(View view, int position) {
RecyclerView.LayoutManager mLockLayoutManager = holder.mLockRecyclerView.getLayoutManager();
int itemCount=mLockLayoutManager.getItemCount();
View item=mLockLayoutManager.getChildAt(position+1);
View item=mLockLayoutManager.getChildAt(position);
item.setBackgroundColor(ContextCompat.getColor(mContext,mOnItemSeletor));
for(int i=0;i<itemCount;i++){
if(i!=position){
mLockLayoutManager.getChildAt(i+1).setBackgroundColor(Color.TRANSPARENT);
mLockLayoutManager.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
}
RecyclerView.LayoutManager mUnLockLayoutManager = holder.mMainRecyclerView.getLayoutManager();
int itemUnLockCount=mUnLockLayoutManager.getItemCount();
View mUnlockItem=mUnLockLayoutManager.getChildAt(position+1);
View mUnlockItem=mUnLockLayoutManager.getChildAt(position);
mUnlockItem.setBackgroundColor(ContextCompat.getColor(mContext,mOnItemSeletor));
for(int i=0;i<itemUnLockCount;i++){
if(i!=position){
mUnLockLayoutManager.getChildAt(i+1).setBackgroundColor(Color.TRANSPARENT);
mUnLockLayoutManager.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
}
}
Expand All @@ -235,8 +233,6 @@ public void onItemSelected(View view, int position) {
if (mOnItemLongClickListenter != null) {
mUnLockAdapter.setOnItemLongClickListenter(mOnItemLongClickListenter);
}
holder.mMainRecyclerView.setPullRefreshEnabled(false);
holder.mMainRecyclerView.setLoadingMoreEnabled(false);
LinearLayoutManager unlockLayoutManager = new LinearLayoutManager(mContext);
unlockLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
holder.mMainRecyclerView.setLayoutManager(unlockLayoutManager);
Expand All @@ -254,14 +250,14 @@ public int getItemCount() {
}

class TableViewHolder extends RecyclerView.ViewHolder {
XRecyclerView mLockRecyclerView;
XRecyclerView mMainRecyclerView;
RecyclerView mLockRecyclerView;
RecyclerView mMainRecyclerView;
CustomHorizontalScrollView mScrollView;

public TableViewHolder(View itemView) {
super(itemView);
mLockRecyclerView = (XRecyclerView) itemView.findViewById(R.id.lock_recyclerview);
mMainRecyclerView = (XRecyclerView) itemView.findViewById(R.id.main_recyclerview);
mLockRecyclerView = (RecyclerView) itemView.findViewById(R.id.lock_recyclerview);
mMainRecyclerView = (RecyclerView) itemView.findViewById(R.id.main_recyclerview);
//解决滑动冲突,只保留最外层RecyclerView的下拉和上拉事件
mLockRecyclerView.setFocusable(false);
mMainRecyclerView.setFocusable(false);
Expand Down
Loading

0 comments on commit 582eefe

Please sign in to comment.