Commit 0c7c2aee authored by 陈前's avatar 陈前

编写了RecyclerView的分割线

parent 81643405
package com.xingdata.zzdpos.ui.main.fragment; package com.xingdata.zzdpos.ui.main.fragment;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.xingdata.zzdpos.C; import com.xingdata.zzdpos.C;
...@@ -17,14 +13,16 @@ import com.xingdata.zzdpos.base.BaseFragment; ...@@ -17,14 +13,16 @@ import com.xingdata.zzdpos.base.BaseFragment;
import com.xingdata.zzdpos.databinding.FragmentCasherBinding; import com.xingdata.zzdpos.databinding.FragmentCasherBinding;
import com.xingdata.zzdpos.ui.main.MainPresenter; import com.xingdata.zzdpos.ui.main.MainPresenter;
import com.xingdata.zzdpos.ui.main.adapter.MenuRecyclerAdapter; import com.xingdata.zzdpos.ui.main.adapter.MenuRecyclerAdapter;
import com.xingdata.zzdpos.util.MyMenuItemDecoration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CasherFragment extends BaseFragment<MainPresenter,FragmentCasherBinding> { public class CasherFragment extends BaseFragment<MainPresenter, FragmentCasherBinding> {
private MenuRecyclerAdapter mMenuRecyclerAdapter; private MenuRecyclerAdapter mMenuRecyclerAdapter;
private List<Integer> integers; private List<Integer> integers;
@Override @Override
public int getLayoutId() { public int getLayoutId() {
return R.layout.fragment_casher; return R.layout.fragment_casher;
...@@ -43,15 +41,15 @@ public class CasherFragment extends BaseFragment<MainPresenter,FragmentCasherBin ...@@ -43,15 +41,15 @@ public class CasherFragment extends BaseFragment<MainPresenter,FragmentCasherBin
integers.add(106); integers.add(106);
mMenuRecyclerAdapter = new MenuRecyclerAdapter(getActivity(), integers); mMenuRecyclerAdapter = new MenuRecyclerAdapter(getActivity(), integers);
mMenuRecyclerAdapter.bindToRecyclerView(mViewBinding.fragmentCasherRecycler); mMenuRecyclerAdapter.bindToRecyclerView(mViewBinding.fragmentCasherRecycler);
// mViewBinding.fragmentCasherRecycler.addItemDecoration(new MyItemDecoration(getActivity(), 2, R.color.black_zhangfei)); mViewBinding.fragmentCasherRecycler.addItemDecoration(new MyMenuItemDecoration(getActivity(),5,getResources().getColor(R.color.gray_kongming)));
mMenuRecyclerAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { mMenuRecyclerAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override @Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) { public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
switch ((int)adapter.getData().get(position)) { switch ((int) adapter.getData().get(position)) {
case C.MENU.MENU_VIP://会员 case C.MENU.MENU_VIP://会员
break; break;
case C.MENU.MENU_RECHARGE://充值 case C.MENU.MENU_RECHARGE://充值
break; break;
case C.MENU.MENU_MS://营销 case C.MENU.MENU_MS://营销
......
...@@ -18,41 +18,41 @@ public class PayAdapter extends BaseAdapter<Pay, ItemPayBinding> { ...@@ -18,41 +18,41 @@ public class PayAdapter extends BaseAdapter<Pay, ItemPayBinding> {
@Override @Override
protected void convert(ItemPayBinding mViewBinding, Pay item) { protected void convert(ItemPayBinding mViewBinding, Pay item) {
int resLogo, resBackground; // int resLogo, resBackground;
switch (item.getPayType()) { // switch (item.getPayType()) {
case C.PAY_CHANNEL.CASH: // case C.PAY_CHANNEL.CASH:
resLogo = R.mipmap.pay_cash; // resLogo = R.mipmap.pay_cash;
resBackground = R.color.red_diaochan; // resBackground = R.color.red_diaochan;
break; // break;
case C.PAY_CHANNEL.WECHAT: // case C.PAY_CHANNEL.WECHAT:
resLogo = R.mipmap.pay_wechat; // resLogo = R.mipmap.pay_wechat;
resBackground = R.color.green_kongrun; // resBackground = R.color.green_kongrun;
break; // break;
case C.PAY_CHANNEL.ALI: // case C.PAY_CHANNEL.ALI:
resLogo = R.mipmap.pay_alipay; // resLogo = R.mipmap.pay_alipay;
resBackground = R.color.blue_yuefei; // resBackground = R.color.blue_yuefei;
break; // break;
case C.PAY_CHANNEL.BANK: // case C.PAY_CHANNEL.BANK:
resLogo = R.mipmap.pay_card; // resLogo = R.mipmap.pay_card;
resBackground = R.color.cyan_liubei; // resBackground = R.color.cyan_liubei;
break; // break;
case C.PAY_CHANNEL.CARD: // case C.PAY_CHANNEL.CARD:
resLogo = R.mipmap.pay_membershipcard; // resLogo = R.mipmap.pay_membershipcard;
resBackground = R.color.yellow_huangxin; // resBackground = R.color.yellow_huangxin;
break; // break;
case C.PAY_CHANNEL.TALLY: // case C.PAY_CHANNEL.TALLY:
resLogo = R.mipmap.pay_credit; // resLogo = R.mipmap.pay_credit;
resBackground = R.color.purple_yanqing; // resBackground = R.color.purple_yanqing;
break; // break;
default: // default:
resLogo = R.mipmap.pay_cash; // resLogo = R.mipmap.pay_cash;
resBackground = R.color.red_diaochan; // resBackground = R.color.red_diaochan;
break; // break;
} // }
mViewBinding.ivLogo.setImageResource(resLogo); // mViewBinding.ivLogo.setImageResource(resLogo);
//
GenericDraweeHierarchy hierarchy = mViewBinding.ivBackground.getHierarchy(); // GenericDraweeHierarchy hierarchy = mViewBinding.ivBackground.getHierarchy();
hierarchy.setBackgroundImage(mContext.getResources().getDrawable(resBackground)); // hierarchy.setBackgroundImage(mContext.getResources().getDrawable(resBackground));
mViewBinding.ivBackground.setHierarchy(hierarchy); // mViewBinding.ivBackground.setHierarchy(hierarchy);
} }
} }
...@@ -12,16 +12,16 @@ import android.view.View; ...@@ -12,16 +12,16 @@ import android.view.View;
* Created by Administrator on 2017/12/21. * Created by Administrator on 2017/12/21.
*/ */
class MyItemDecoration extends RecyclerView.ItemDecoration { public class MyMenuItemDecoration extends RecyclerView.ItemDecoration {
private Drawable mDividerDarwable; private Drawable mDividerDarwable;
private int mDividerHight = 1; private int mDividerHight = 1;
private Paint mColorPaint; private Paint mColorPaint;
private int size=2; private int size = 2;
public final int[] ATRRS = new int[]{android.R.attr.listDivider}; public final int[] ATRRS = new int[]{android.R.attr.listDivider};
public MyItemDecoration(Context context) { public MyMenuItemDecoration(Context context) {
final TypedArray ta = context.obtainStyledAttributes(ATRRS); final TypedArray ta = context.obtainStyledAttributes(ATRRS);
this.mDividerDarwable = ta.getDrawable(0); this.mDividerDarwable = ta.getDrawable(0);
ta.recycle(); ta.recycle();
...@@ -31,7 +31,7 @@ class MyItemDecoration extends RecyclerView.ItemDecoration { ...@@ -31,7 +31,7 @@ class MyItemDecoration extends RecyclerView.ItemDecoration {
int dividerHight 分割线的线宽 int dividerHight 分割线的线宽
int dividerColor 分割线的颜色 int dividerColor 分割线的颜色
*/ */
public MyItemDecoration(Context context, int dividerHight, int dividerColor) { public MyMenuItemDecoration(Context context, int dividerHight, int dividerColor) {
this(context); this(context);
mDividerHight = dividerHight; mDividerHight = dividerHight;
mColorPaint = new Paint(); mColorPaint = new Paint();
...@@ -42,18 +42,19 @@ class MyItemDecoration extends RecyclerView.ItemDecoration { ...@@ -42,18 +42,19 @@ class MyItemDecoration extends RecyclerView.ItemDecoration {
int dividerHight 分割线的线宽 int dividerHight 分割线的线宽
int dividerColor 分割线的颜色 int dividerColor 分割线的颜色
*/ */
public MyItemDecoration(Context context, int dividerHight, int dividerColor, int size) { public MyMenuItemDecoration(Context context, int dividerHight, int dividerColor, int size) {
this(context); this(context);
mDividerHight = dividerHight; mDividerHight = dividerHight;
mColorPaint = new Paint(); mColorPaint = new Paint();
mColorPaint.setColor(dividerColor); mColorPaint.setColor(dividerColor);
this.size=size; this.size = size;
} }
/* /*
int dividerHight 分割线的线宽 int dividerHight 分割线的线宽
Drawable dividerDrawable 图片分割线 Drawable dividerDrawable 图片分割线
*/ */
public MyItemDecoration(Context context, int dividerHight, Drawable dividerDrawable) { public MyMenuItemDecoration(Context context, int dividerHight, Drawable dividerDrawable) {
this(context); this(context);
mDividerHight = dividerHight; mDividerHight = dividerHight;
mDividerDarwable = dividerDrawable; mDividerDarwable = dividerDrawable;
...@@ -73,8 +74,8 @@ class MyItemDecoration extends RecyclerView.ItemDecoration { ...@@ -73,8 +74,8 @@ class MyItemDecoration extends RecyclerView.ItemDecoration {
final View child = parent.getChildAt(i); final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int top = child.getTop() - params.topMargin+30; final int top = child.getTop() - params.topMargin + 30;
final int bottom = child.getBottom() + params.bottomMargin-30; final int bottom = child.getBottom() + params.bottomMargin - 30;
int left = 0; int left = 0;
int right = 0; int right = 0;
...@@ -108,8 +109,8 @@ class MyItemDecoration extends RecyclerView.ItemDecoration { ...@@ -108,8 +109,8 @@ class MyItemDecoration extends RecyclerView.ItemDecoration {
final View child = parent.getChildAt(i); final View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int left = child.getLeft() - params.leftMargin - mDividerHight; final int left = child.getLeft() - params.leftMargin - mDividerHight+30;
final int right = child.getRight() + params.rightMargin; final int right = child.getRight() + params.rightMargin-30;
int top = 0; int top = 0;
int bottom = 0; int bottom = 0;
...@@ -127,9 +128,11 @@ class MyItemDecoration extends RecyclerView.ItemDecoration { ...@@ -127,9 +128,11 @@ class MyItemDecoration extends RecyclerView.ItemDecoration {
// top = child.getBottom() + params.bottomMargin; // top = child.getBottom() + params.bottomMargin;
// bottom = top + mDividerHight; // bottom = top + mDividerHight;
// } else { // } else {
// if (i!=) if (i/size!=(parent.getAdapter().getItemCount()/size-1)){
top = child.getBottom() + params.bottomMargin; top = child.getBottom() + params.bottomMargin;
bottom = top + mDividerHight; bottom = top + mDividerHight;
}
// } // }
//画分割线 //画分割线
mDividerDarwable.setBounds(left, top, right, bottom); mDividerDarwable.setBounds(left, top, right, bottom);
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
android:layout_marginBottom="@dimen/all_padding" android:layout_marginBottom="@dimen/all_padding"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:background="@color/gray_zhouyu" android:background="@color/white_caocao"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout> <layout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="25dp"
android:paddingBottom="25dp"
android:gravity="center"
android:elevation="0.5dp"
android:background="@color/white_caocao"
android:layout_margin="0.8dp"
android:orientation="vertical">
<ImageView <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/img" android:id="@+id/ll"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="4dp"/> android:layout_margin="0.8dp"
android:background="@color/white_caocao"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="25dp"
android:paddingTop="25dp">
<TextView <ImageView
android:id="@+id/text" android:id="@+id/img"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:layout_margin="4dp" />
</LinearLayout> <TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black_baozheng" />
</LinearLayout>
</layout> </layout>
...@@ -124,6 +124,7 @@ ...@@ -124,6 +124,7 @@
<color name="gray_zhouyu">#f1f3f7</color> <color name="gray_zhouyu">#f1f3f7</color>
<color name="gray_huanggai">#afb9c3</color> <color name="gray_huanggai">#afb9c3</color>
<color name="gray_kongming">#e6e6e6</color>
<color name="white_caocao">#ffffff</color> <color name="white_caocao">#ffffff</color>
...@@ -144,6 +145,8 @@ ...@@ -144,6 +145,8 @@
<color name="yellow_huangxin">#ffc960</color> <color name="yellow_huangxin">#ffc960</color>
<color name="golden_yuji">#f2e7d3</color>
<color name="purple_yanqing">#6590e6</color> <color name="purple_yanqing">#6590e6</color>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment