[add] 尝试添加footer实现蒙层+滑动
This commit is contained in:
@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -25,6 +26,11 @@ public class CheckInfoAdapter extends RecyclerView.Adapter {
|
||||
private Context mContext;
|
||||
private String mStyle;
|
||||
private List<CheckResultData.CheckListItem> showData;
|
||||
//item类型
|
||||
public static final int ITEM_TYPE_CONTENT = 0;//内容
|
||||
public static final int ITEM_TYPE_BOTTOM = 1;//footer类型
|
||||
//底部View个数
|
||||
private int mBottomCount = 1;
|
||||
|
||||
public CheckInfoAdapter(Context context, String style, List checkResultData) {
|
||||
mContext = context;
|
||||
@@ -36,6 +42,12 @@ public class CheckInfoAdapter extends RecyclerView.Adapter {
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_TYPE_BOTTOM) {
|
||||
View v = mLayoutInflater.inflate(R.layout.check_recycler_footer, parent,
|
||||
false);
|
||||
CheckInfoAdapter.CheckInfoFooter holder = new CheckInfoAdapter.CheckInfoFooter(v);
|
||||
return holder;
|
||||
}
|
||||
View v = mLayoutInflater.inflate(R.layout.check_info_adapter, parent,
|
||||
false);
|
||||
CheckInfoAdapter.CheckInfoViewHolder holder = new CheckInfoAdapter.CheckInfoViewHolder(v);
|
||||
@@ -46,23 +58,25 @@ public class CheckInfoAdapter extends RecyclerView.Adapter {
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
try {
|
||||
if (position < showData.size() * 2) {
|
||||
int index = position / 2;
|
||||
CheckResultData.CheckListItem positionItem = showData.get(index);
|
||||
if (isEven(position) == true) {//偶数隐藏图片显示检测指标
|
||||
((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.GONE);
|
||||
((CheckInfoViewHolder) holder).mTextView.setText(positionItem.getName());
|
||||
} else {//奇数显示图片和检测指标结果
|
||||
((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.VISIBLE);
|
||||
String state = (String) positionItem.getStateValue();
|
||||
if (state.equals("1")) {
|
||||
((CheckInfoViewHolder) holder).mTextView.setText("正常");
|
||||
((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_right);
|
||||
} else if ((state.equals("0"))) {
|
||||
((CheckInfoViewHolder) holder).mTextView.setText("异常");
|
||||
((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_wrong);
|
||||
} else {
|
||||
((CheckInfoViewHolder) holder).mTextView.setText(state);
|
||||
if (holder instanceof CheckInfoAdapter.CheckInfoViewHolder) {
|
||||
if (position < showData.size() * 2) {
|
||||
int index = position / 2;
|
||||
CheckResultData.CheckListItem positionItem = showData.get(index);
|
||||
if (isEven(position) == true) {//偶数隐藏图片显示检测指标
|
||||
((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.GONE);
|
||||
((CheckInfoViewHolder) holder).mTextView.setText(positionItem.getName());
|
||||
} else {//奇数显示图片和检测指标结果
|
||||
((CheckInfoViewHolder) holder).checkIcon.setVisibility(View.VISIBLE);
|
||||
String state = (String) positionItem.getStateValue();
|
||||
if (state.equals("1")) {
|
||||
((CheckInfoViewHolder) holder).mTextView.setText("正常");
|
||||
((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_right);
|
||||
} else if ((state.equals("0"))) {
|
||||
((CheckInfoViewHolder) holder).mTextView.setText("异常");
|
||||
((CheckInfoViewHolder) holder).checkIcon.setImageResource(R.drawable.check_wrong);
|
||||
} else {
|
||||
((CheckInfoViewHolder) holder).mTextView.setText(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +97,7 @@ public class CheckInfoAdapter extends RecyclerView.Adapter {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return showData.size() * 2;
|
||||
return showData.size() * 2 + mBottomCount;
|
||||
}
|
||||
|
||||
public class CheckInfoViewHolder extends RecyclerView.ViewHolder {
|
||||
@@ -97,8 +111,17 @@ public class CheckInfoAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
public class CheckInfoFooter extends RecyclerView.ViewHolder {
|
||||
public CheckInfoFooter(View v) {
|
||||
super(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
if (position > showData.size() * 2) {
|
||||
return ITEM_TYPE_BOTTOM;
|
||||
}
|
||||
return ITEM_TYPE_CONTENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.eagle.core.function.check.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import com.mogo.eagle.core.function.check.R;
|
||||
|
||||
import java.util.jar.Attributes;
|
||||
|
||||
/**
|
||||
* @author liujing
|
||||
* @description 描述
|
||||
* @since: 10/13/21
|
||||
*/
|
||||
public class CheckRecyclerFooter extends View {
|
||||
|
||||
public CheckRecyclerFooter(Context context, AttributeSet attributes) {
|
||||
super(context, attributes);
|
||||
LayoutInflater.from(context).inflate(R.layout.check_recycler_footer, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_300"
|
||||
android:background="@color/check_list_item_back">
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user