当前位置:   article > 正文

Android之 日历单选多选控件_android日历控件

android日历控件

一,效果图

1.1 单选

 2.2 多选

二 实现思路

2.1 数据来源,利用原生日历Calendar,获取从本月开始的往后一年的日期,遍历月数添加全部天数据

  1. private void initCalendarData() {
  2. Calendar calendar = Calendar.getInstance();
  3. year = calendar.get(Calendar.YEAR);
  4. month = calendar.get(Calendar.MONTH);
  5. day = calendar.get(Calendar.DAY_OF_MONTH);
  6. nowDay = day;
  7. calendar.set(year, month, 1);
  8. for (int i = 0; i < 12; i++) {
  9. List<DateEntity> deList = new ArrayList<>();
  10. MonthEntity monthEntity = new MonthEntity();
  11. int maxDayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
  12. int empty = calendar.get(Calendar.DAY_OF_WEEK);
  13. empty = empty == 1 ? 6 : empty - 2;
  14. for (int j = 0; j < empty; j++) {
  15. DateEntity de = new DateEntity();
  16. de.setType(1);
  17. deList.add(de);
  18. }
  19. for (int j = 1; j <= maxDayOfMonth; j++) {
  20. DateEntity de = new DateEntity();
  21. if (i == 0) {
  22. de.setType(j < nowDay ? 4 : 0);
  23. } else {
  24. de.setType(0);
  25. }
  26. de.setDate(j);
  27. if (i == 0 && nowDay == j) {
  28. de.setToday(true);
  29. } else {
  30. de.setToday(false);
  31. }
  32. de.setParentPos(i);
  33. String[] result=DatePickerUtils.getLunarDate(year, month + 1, j);
  34. de.setDesType(result[0]);
  35. de.setDesc(result[1]);
  36. deList.add(de);
  37. }
  38. year = calendar.get(Calendar.YEAR);
  39. month = calendar.get(Calendar.MONTH) + 1;
  40. monthEntity.setTitle(year + "年" + month + "月");
  41. monthEntity.setYear(year);
  42. monthEntity.setMonth(month);
  43. monthEntity.setList(deList);
  44. monthList.add(monthEntity);
  45. calendar.add(Calendar.MONTH, 1);
  46. }
  47. }

2.2 添加公立,农历,节气数据。下面只是节假日的判断。

  1. private static String getChinaCalendarMsg(int year, int month, int day) {
  2. String message = "";
  3. if (((month) == 1) && day == 1) {
  4. message = "春节";
  5. } else if (((month) == 1) && day == 15) {
  6. message = "元宵";
  7. } else if (((month) == 5) && day == 5) {
  8. message = "端午";
  9. } else if ((month == 7) && day == 7) {
  10. message = "七夕";
  11. } else if (((month) == 8) && day == 15) {
  12. message = "中秋";
  13. } else if ((month == 9) && day == 9) {
  14. message = "重阳";
  15. } else if ((month == 12) && day == 8) {
  16. message = "腊八";
  17. } else {
  18. if (month == 12) {
  19. if ((((monthDays(year, month) == 29) && day == 29))
  20. || ((((monthDays(year, month) == 30) && day == 30)))) {
  21. message = "除夕";
  22. }
  23. }
  24. }
  25. return message;
  26. }

2.3 控件,可以用两层Recycleview,但最好不要这样做,嵌套体验是非常差的,明显的卡顿。所以尽量用一个Recycleview,利用getItemViewType来避免嵌套。

  1. @Override
  2. public int getItemViewType(int position) {
  3. if (isEmptyPosition(position)) {
  4. // 空布局
  5. return TYPE_EMPTY;
  6. }
  7. mTempPosition = position;
  8. int groupPosition = getGroupPositionForPosition(position);
  9. int type = judgeType(position);
  10. if (type == TYPE_HEADER) {
  11. return getHeaderViewType(groupPosition);
  12. } else if (type == TYPE_FOOTER) {
  13. return getFooterViewType(groupPosition);
  14. } else if (type == TYPE_CHILD) {
  15. int childPosition = getChildPositionForPosition(groupPosition, position);
  16. return getChildViewType(groupPosition, childPosition);
  17. }
  18. return super.getItemViewType(position);
  19. }

三, 核心源码

3.1 项目结构

3.2 CalendarSelectDialog.java

  1. public class CalendarSelectDialog extends Dialog {
  2. private ImageView icClose;
  3. private RecyclerView rvCalendar;
  4. private TextView tvSure;
  5. private Activity context;
  6. private CalendarGroupedListAdapter groupedListAdapter;
  7. private List<MonthEntity> monthList = new ArrayList<>();
  8. private int year, month, day;
  9. private int nowDay;
  10. private int lastDateSelect = -1, lastMonthSelect = -1;
  11. public interface OnViewClickLiatener {
  12. void sureClick(String selectTime);
  13. void cancelClick();
  14. }
  15. public OnViewClickLiatener onViewClickLiatener;
  16. public void setOnViewClickLiatener(OnViewClickLiatener onViewClickLiatener) {
  17. this.onViewClickLiatener = onViewClickLiatener;
  18. }
  19. public CalendarSelectDialog(Activity context) {
  20. super(context, R.style.custom_dialog2);
  21. this.context = context;
  22. }
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.dialog_caledar_select);
  27. setCanceledOnTouchOutside(true);
  28. WindowManager.LayoutParams params = getWindow().getAttributes();
  29. params.width = ScreenUtils.getScreenWidth(context);
  30. params.height = (int) (ScreenUtils.getTotalScreenHeight(context)*0.85f);
  31. getWindow().setGravity(Gravity.BOTTOM);
  32. getWindow().setAttributes(params);
  33. getWindow().setBackgroundDrawableResource(R.color.transparent);
  34. getWindow().setWindowAnimations(R.style.pop_animation_bottom);
  35. initView();
  36. setData();
  37. }
  38. public void initView() {
  39. icClose = (ImageView) findViewById(R.id.ic_close);
  40. rvCalendar = (RecyclerView) findViewById(R.id.rv_calendar);
  41. tvSure = (TextView) findViewById(R.id.tv_sure);
  42. }
  43. public void setData() {
  44. icClose.setOnClickListener(new View.OnClickListener() {
  45. @Override
  46. public void onClick(View view) {
  47. dismiss();
  48. if (onViewClickLiatener != null) {
  49. onViewClickLiatener.cancelClick();
  50. }
  51. }
  52. });
  53. tvSure.setOnClickListener(new View.OnClickListener() {
  54. @Override
  55. public void onClick(View view) {
  56. if(lastMonthSelect<0){
  57. ToastHelp.showToast("请选择日期");
  58. return;
  59. }
  60. dismiss();
  61. MonthEntity monthEntity=monthList.get(lastMonthSelect);
  62. DateEntity dateEntity=monthEntity.getList().get(lastDateSelect);
  63. int year=monthEntity.getYear();
  64. int month=monthEntity.getMonth();
  65. int date=dateEntity.getDate();
  66. String monthString;
  67. if(month<10){
  68. monthString="0"+month;
  69. }else {
  70. monthString=String.valueOf(month);
  71. }
  72. String dataString;
  73. if(date<10){
  74. dataString="0"+date;
  75. }else {
  76. dataString=String.valueOf(date);
  77. }
  78. String selectTime=year+"-"+monthString+"-"+dataString;
  79. if (onViewClickLiatener != null) {
  80. onViewClickLiatener.sureClick(selectTime);
  81. }
  82. }
  83. });
  84. CalendarUtils.init(context);
  85. initCalendarData();
  86. initCalendarRv();
  87. }
  88. @Override
  89. public void dismiss() {
  90. if (context == null || ((Activity) context).isDestroyed() || ((Activity) context).isFinishing()) {
  91. return;
  92. }
  93. super.dismiss();
  94. }
  95. @Override
  96. public void show() {
  97. if (context == null || ((Activity) context).isDestroyed() || ((Activity) context).isFinishing()) {
  98. return;
  99. }
  100. super.show();
  101. }
  102. private void initCalendarData() {
  103. Calendar calendar = Calendar.getInstance();
  104. year = calendar.get(Calendar.YEAR);
  105. month = calendar.get(Calendar.MONTH);
  106. day = calendar.get(Calendar.DAY_OF_MONTH);
  107. nowDay = day;
  108. calendar.set(year, month, 1);
  109. for (int i = 0; i < 12; i++) {
  110. List<DateEntity> deList = new ArrayList<>();
  111. MonthEntity monthEntity = new MonthEntity();
  112. int maxDayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
  113. int empty = calendar.get(Calendar.DAY_OF_WEEK);
  114. empty = empty == 1 ? 6 : empty - 2;
  115. for (int j = 0; j < empty; j++) {
  116. DateEntity de = new DateEntity();
  117. de.setType(1);
  118. deList.add(de);
  119. }
  120. for (int j = 1; j <= maxDayOfMonth; j++) {
  121. DateEntity de = new DateEntity();
  122. if (i == 0) {
  123. de.setType(j < nowDay ? 4 : 0);
  124. } else {
  125. de.setType(0);
  126. }
  127. de.setDate(j);
  128. if (i == 0 && nowDay == j) {
  129. de.setToday(true);
  130. } else {
  131. de.setToday(false);
  132. }
  133. de.setParentPos(i);
  134. String[] result=DatePickerUtils.getLunarDate(year, month + 1, j);
  135. de.setDesType(result[0]);
  136. de.setDesc(result[1]);
  137. deList.add(de);
  138. }
  139. year = calendar.get(Calendar.YEAR);
  140. month = calendar.get(Calendar.MONTH) + 1;
  141. monthEntity.setTitle(year + "年" + month + "月");
  142. monthEntity.setYear(year);
  143. monthEntity.setMonth(month);
  144. monthEntity.setList(deList);
  145. monthList.add(monthEntity);
  146. calendar.add(Calendar.MONTH, 1);
  147. }
  148. }
  149. private void initCalendarRv() {
  150. groupedListAdapter =new CalendarGroupedListAdapter(context,monthList);
  151. GroupedGridLayoutManager gridLayoutManager = new GroupedGridLayoutManager(context, 7, groupedListAdapter);
  152. rvCalendar.setLayoutManager(gridLayoutManager);
  153. rvCalendar.getItemAnimator().setChangeDuration(0);
  154. rvCalendar.setAdapter(groupedListAdapter);
  155. groupedListAdapter.setOnItemClickListener(new CalendarGroupedListAdapter.OnItemClickListener() {
  156. @Override
  157. public void itemClick(int groupPosition, int childPosition) {
  158. //setRangeClick(groupPosition,childPosition);
  159. setSingleClick(groupPosition,childPosition);
  160. }
  161. });
  162. }
  163. private void getViews() {
  164. rvCalendar = (RecyclerView) findViewById(R.id.rv_calendar);
  165. }
  166. /**
  167. *
  168. * @param groupPosition
  169. * @param childPosition
  170. */
  171. private void setSingleClick(int groupPosition, int childPosition){
  172. if (groupPosition == lastMonthSelect && childPosition == lastDateSelect) {
  173. return;
  174. }
  175. monthList.get(groupPosition).getList().get(childPosition).setType(8);
  176. groupedListAdapter.notifyChildChanged(groupPosition, childPosition);
  177. if (lastDateSelect != -1) {
  178. monthList.get(lastMonthSelect).getList().get(lastDateSelect).setType(0);
  179. groupedListAdapter.notifyChildChanged(lastMonthSelect, lastDateSelect);
  180. }
  181. lastMonthSelect = groupPosition;
  182. lastDateSelect = childPosition;
  183. }
  184. /**
  185. * 范围选择
  186. */
  187. private boolean selectComplete;
  188. private List<Integer> selectMonth = new ArrayList<>();
  189. private List<Integer> selectDate = new ArrayList<>();
  190. private void setRangeClick(int parentPos, int pos){
  191. if (parentPos != lastMonthSelect || pos != lastDateSelect) {
  192. //1、第二次选择;2、选择的月份相等日期比之前选择的大或者选择的月份比之前的大;3、选择未完成
  193. boolean haveMiddle = lastMonthSelect != -1 && ((lastMonthSelect == parentPos && pos > lastDateSelect) || (parentPos > lastMonthSelect))
  194. && !selectComplete;
  195. if (haveMiddle) {
  196. monthList.get(parentPos).getList().get(pos).setType(6);
  197. selectDate.add(1);
  198. monthList.get(lastMonthSelect).getList().get(lastDateSelect).setType(7);
  199. selectDate.add(1);
  200. int monthLen = parentPos - lastMonthSelect;
  201. List<DateEntity> list;
  202. int dateLen;
  203. if (monthLen == 0) {
  204. dateLen = pos - lastDateSelect;
  205. for (int i = 1; i < dateLen; i++) {
  206. monthList.get(parentPos).getList().get(i + lastDateSelect).setType(5);
  207. selectDate.add(1);
  208. }
  209. groupedListAdapter.notifyGroupChanged(lastMonthSelect);
  210. //选择了这个月
  211. selectMonth.add(parentPos);
  212. } else {
  213. //第一个月
  214. int lastMonthSize = monthList.get(lastMonthSelect).getList().size();
  215. dateLen = lastMonthSize - lastDateSelect;
  216. for (int i = 1; i < dateLen; i++) {
  217. monthList.get(lastMonthSelect).getList().get(i + lastDateSelect).setType(5);
  218. selectDate.add(1);
  219. }
  220. groupedListAdapter.notifyGroupChanged(lastMonthSelect);
  221. //选择了这个月
  222. selectMonth.add(lastMonthSelect);
  223. //中间月份
  224. int month;
  225. int middleMonthLen = parentPos - lastMonthSelect;
  226. for (int i = 1; i < middleMonthLen; i++) {
  227. month = lastMonthSelect + i;
  228. list = monthList.get(month).getList();
  229. dateLen = list.size();
  230. for (int j = 0; j < dateLen; j++) {
  231. if (list.get(j).getType() != 1) {
  232. list.get(j).setType(5);
  233. selectDate.add(1);
  234. }
  235. }
  236. groupedListAdapter.notifyGroupChanged(month);
  237. //选择了这个月
  238. selectMonth.add(month);
  239. }
  240. //最后那个月
  241. dateLen = pos;
  242. for (int i = 0; i < dateLen; i++) {
  243. DateEntity de = monthList.get(parentPos).getList().get(i);
  244. if (de.getType() != 1) {
  245. de.setType(5);
  246. selectDate.add(1);
  247. }
  248. }
  249. groupedListAdapter.notifyGroupChanged(parentPos);
  250. //选择了这个月
  251. selectMonth.add(parentPos);
  252. }
  253. Log.d("mita", "选择的天数:" + selectDate.size());
  254. selectComplete = true;
  255. lastMonthSelect = -1;
  256. lastDateSelect = -1;
  257. } else {
  258. selectDate.clear();
  259. //清除已选
  260. if (selectComplete) {
  261. List<DateEntity> list;
  262. DateEntity de;
  263. int len = selectMonth.size();
  264. for (int i = 0; i < len; i++) {
  265. list = monthList.get(selectMonth.get(i)).getList();
  266. int size = list.size();
  267. for (int j = 0; j < size; j++) {
  268. de = list.get(j);
  269. if (de.getType() == 5 || de.getType() == 6 || de.getType() == 7) {
  270. de.setType(0);
  271. }
  272. }
  273. groupedListAdapter.notifyGroupChanged(selectMonth.get(i));
  274. }
  275. selectMonth.clear();
  276. }
  277. monthList.get(parentPos).getList().get(pos).setType(3);
  278. groupedListAdapter.notifyGroupChanged(parentPos);
  279. if (lastDateSelect != -1) {
  280. monthList.get(lastMonthSelect).getList().get(lastDateSelect).setType(0);
  281. groupedListAdapter.notifyGroupChanged(lastMonthSelect);
  282. }
  283. lastMonthSelect = parentPos;
  284. lastDateSelect = pos;
  285. selectComplete = false;
  286. }
  287. }
  288. }
  289. }

3.2 CalendarGroupedListAdapter.java

  1. public class CalendarGroupedListAdapter extends GroupedRecyclerViewAdapter {
  2. private List<MonthEntity> groupList;
  3. private Context context;
  4. public CalendarGroupedListAdapter(Context context, List<MonthEntity> groupList) {
  5. super(context);
  6. this.context = context;
  7. this.groupList = groupList;
  8. }
  9. @Override
  10. public int getGroupCount() {
  11. return groupList.size();
  12. }
  13. @Override
  14. public int getChildrenCount(int groupPosition) {
  15. return groupList.get(groupPosition).getList().size();
  16. }
  17. @Override
  18. public boolean hasHeader(int groupPosition) {
  19. return true;
  20. }
  21. @Override
  22. public boolean hasFooter(int groupPosition) {
  23. return false;
  24. }
  25. @Override
  26. public int getHeaderLayout(int viewType) {
  27. return R.layout.item_calendar;
  28. }
  29. @Override
  30. public int getFooterLayout(int viewType) {
  31. return 0;
  32. }
  33. @Override
  34. public int getChildLayout(int viewType) {
  35. return R.layout.item_date;
  36. }
  37. @Override
  38. public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) {
  39. MonthEntity monthEntity = groupList.get(groupPosition);
  40. holder.setText(R.id.tv_cal_title, monthEntity.getTitle());
  41. }
  42. @Override
  43. public void onBindFooterViewHolder(BaseViewHolder holder, int groupPosition) {
  44. }
  45. @Override
  46. public void onBindChildViewHolder(BaseViewHolder holder, final int groupPosition, final int childPosition) {
  47. DateEntity dateEntity = groupList.get(groupPosition).getList().get(childPosition);
  48. LinearLayout llDate = holder.get(R.id.ll_date);
  49. TextView mTvDate = holder.get(R.id.tv_date);
  50. TextView mTvDesc = holder.get(R.id.tv_desc);
  51. TextView mTvToday = holder.get(R.id.tv_today);
  52. mTvToday.setText("今日");
  53. int date = dateEntity.getDate();
  54. int type = dateEntity.getType();
  55. boolean isToday = dateEntity.isToday();
  56. if (type == 1) {//留白
  57. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  58. mTvToday.setTextColor(Color.TRANSPARENT);
  59. mTvDate.setText("");
  60. mTvDesc.setText("");
  61. mTvDate.setTextColor(Color.TRANSPARENT);
  62. mTvDesc.setTextColor(Color.TRANSPARENT);
  63. llDate.setBackgroundColor(Color.TRANSPARENT);
  64. llDate.setEnabled(false);
  65. } else if (type == 0) {//日常
  66. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  67. mTvDate.setText(String.valueOf(dateEntity.getDate()));
  68. mTvDesc.setText(dateEntity.getDesc());
  69. mTvToday.setTextColor(ContextCompat.getColor(context, R.color.color_red));
  70. mTvDate.setTextColor(ContextCompat.getColor(context, R.color.color_333333));
  71. mTvDesc.setTextColor(TextUtils.isEmpty(dateEntity.getDesType()) ? ContextCompat.getColor(context, R.color.color_333333) : ContextCompat.getColor(context, R.color.color_red));
  72. llDate.setBackgroundColor(Color.TRANSPARENT);
  73. llDate.setEnabled(true);
  74. } else if (type == 3) {//日常选中
  75. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  76. mTvDate.setText(String.valueOf(dateEntity.getDate()));
  77. mTvDesc.setText(dateEntity.getDesc());
  78. mTvToday.setTextColor(ContextCompat.getColor(context, R.color.white));
  79. mTvDate.setTextColor(ContextCompat.getColor(context, R.color.white));
  80. mTvDesc.setTextColor(ContextCompat.getColor(context, R.color.white));
  81. llDate.setBackgroundResource(R.drawable.state_selected);
  82. llDate.setClickable(true);
  83. } else if (type == 4) {//今天之前的日期
  84. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  85. mTvDate.setText(String.valueOf(dateEntity.getDate()));
  86. mTvDesc.setText(dateEntity.getDesc());
  87. mTvToday.setTextColor(ContextCompat.getColor(context, R.color.color_cccccc));
  88. mTvDate.setTextColor(ContextCompat.getColor(context, R.color.color_cccccc));
  89. mTvDesc.setTextColor(ContextCompat.getColor(context, R.color.color_cccccc));
  90. llDate.setBackgroundColor(Color.TRANSPARENT);
  91. llDate.setEnabled(false);
  92. } else if (type == 5) {//中间
  93. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  94. mTvDate.setText(String.valueOf(dateEntity.getDate()));
  95. mTvDesc.setText(dateEntity.getDesc());
  96. mTvToday.setTextColor(ContextCompat.getColor(context, R.color.white));
  97. mTvDate.setTextColor(ContextCompat.getColor(context, R.color.white));
  98. mTvDesc.setTextColor(ContextCompat.getColor(context, R.color.white));
  99. llDate.setBackgroundResource(R.drawable.state_middle_range);
  100. llDate.setEnabled(true);
  101. } else if (type == 6) {//终点
  102. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  103. mTvDate.setText(String.valueOf(dateEntity.getDate()));
  104. mTvDesc.setText("结束");
  105. mTvToday.setTextColor(ContextCompat.getColor(context, R.color.white));
  106. mTvDate.setTextColor(ContextCompat.getColor(context, R.color.white));
  107. mTvDesc.setTextColor(ContextCompat.getColor(context, R.color.white));
  108. llDate.setBackgroundResource(R.drawable.state_end_range);
  109. llDate.setEnabled(true);
  110. } else if (type == 7) {//起点
  111. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  112. mTvDate.setText(String.valueOf(dateEntity.getDate()));
  113. mTvDesc.setText("开始");
  114. mTvToday.setTextColor(ContextCompat.getColor(context, R.color.white));
  115. mTvDate.setTextColor(ContextCompat.getColor(context, R.color.white));
  116. mTvDesc.setTextColor(ContextCompat.getColor(context, R.color.white));
  117. llDate.setBackgroundResource(R.drawable.state_first_range);
  118. llDate.setEnabled(true);
  119. } else if (type == 8) {//单选
  120. mTvToday.setVisibility(isToday ? View.VISIBLE : View.INVISIBLE);
  121. mTvDate.setText(String.valueOf(dateEntity.getDate()));
  122. mTvDesc.setText(dateEntity.getDesc());
  123. mTvToday.setTextColor(ContextCompat.getColor(context, R.color.white));
  124. mTvDate.setTextColor(ContextCompat.getColor(context, R.color.white));
  125. mTvDesc.setTextColor(ContextCompat.getColor(context, R.color.white));
  126. llDate.setBackgroundResource(R.drawable.state_selected);
  127. llDate.setEnabled(true);
  128. }
  129. llDate.setOnClickListener(new View.OnClickListener() {
  130. @Override
  131. public void onClick(View v) {
  132. if (onItemClickListener != null) {
  133. onItemClickListener.itemClick(groupPosition, childPosition);
  134. }
  135. }
  136. });
  137. }
  138. public interface OnItemClickListener {
  139. void itemClick(int groupPosition, int childPosition);
  140. }
  141. public OnItemClickListener onItemClickListener;
  142. public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
  143. this.onItemClickListener = onItemClickListener;
  144. }
  145. }

四,注意

4.1 由于左右留白,父控件Recycleview做了外边距margin,会导致子控件左右也有边距。但UI要求是无边距的,这个时候就需要特殊处理控件。

  1. <androidx.recyclerview.widget.RecyclerView
  2.     android:id="@+id/rv_calendar"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:layout_marginLeft="12dp"
  6.     android:layout_marginRight="12dp"
  7.     android:overScrollMode="never"/>

 

4.2 方法,可以用裁剪属性clipChildren,来控制他的子控件是否要在他应有的边界内进行绘制

android:clipChildren=“false” 就是不限制他子控件在其边界内进行绘制
android:clipChildren=“true” 限制他子控件在其边界内进行绘制

 4.3 clipChildren需要特别注意,加在RecyclerView父控件是没用的,只能加载RecyclerView的父控件,即需要需要裁剪的view的爷辈控件。如下:添加属性android:clipChildren="false"

  1. <FrameLayout
  2. android:layout_width="match_parent"
  3. android:layout_height="0dp"
  4. android:layout_weight="1"
  5. android:clipChildren="false">
  6. <androidx.recyclerview.widget.RecyclerView
  7. android:id="@+id/rv_calendar"
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:layout_marginLeft="12dp"
  11. android:layout_marginRight="12dp"
  12. android:overScrollMode="never"/>
  13. </FrameLayout>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/534798
推荐阅读
相关标签
  

闽ICP备14008679号