public class Maindashboard extends AppCompatActivity {
ArrayList<SectionDataModel> allSampleData;
private Toolbar toolbar;
public static TextView title;
public static RecyclerView my_recycler_view;
@SuppressLint("WrongConstant")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main2);
allSampleData = new ArrayList<SectionDataModel>();
title = findViewById(R.id.title);
ArrayList<String> years = new ArrayList<String>();
int thisYear = Calendar.getInstance().get(Calendar.YEAR) + 10;
for (int ik = 2019; ik <= thisYear; ik++) {
years.add(Integer.toString(ik));
int year = ik;
}
my_recycler_view = (RecyclerView) findViewById(R.id.rv_item);
my_recycler_view.setHasFixedSize(true);
RecyclerViewDataAdapter adapter = new RecyclerViewDataAdapter(Maindashboard.this, allSampleData);
my_recycler_view.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
my_recycler_view.setItemViewCacheSize(20);
my_recycler_view.setDrawingCacheEnabled(true);
my_recycler_view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
my_recycler_view.setRecycledViewPool(new RecyclerView.RecycledViewPool());
my_recycler_view.setAdapter(adapter);
createDummyData();
}
public void createDummyData() {
for (int j = 0; j < 132; j++) {
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH);
SectionDataModel dm = new SectionDataModel();
ArrayList<SingleItemModel> singleItem = new ArrayList<SingleItemModel>();
// cal.set(Calendar.DAY_OF_YEAR, 2019);
cal.set(Calendar.MONTH, month + j);
SimpleDateFormat dfs = new SimpleDateFormat("MMMM-yyyy");
String months = dfs.format(cal.getTime());
dm.setHeaderTitle(months);
int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
SimpleDateFormat df = new SimpleDateFormat("dd-MMMM-yyyy");
//System.out.print(df.format(cal.getTime()));
cal.set(Calendar.DAY_OF_MONTH, 1);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
for (int i = 1; i < maxDay + dayOfWeek; i++) {
SingleItemModel imageModel = new SingleItemModel();
if (i < dayOfWeek) {
imageModel.setName(" - - ");
} else {
int index = i - dayOfWeek + 1;
cal.set(Calendar.DAY_OF_MONTH, index);
imageModel.setName(df.format(cal.getTime()));
}
singleItem.add(imageModel);
}
dm.setAllItemsInSection(singleItem);
allSampleData.add(dm);
}
}
public int getWeekdayOfMonth(int year, int month) {
Calendar cal = Calendar.getInstance();
cal.set(year, month - 1, 1);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;
return dayOfWeek;
}
}
我创建了自定义垂直滚动10年日历视图,它的工作原理不错,但不能平滑滚动,当打开日历屏幕时,它需要5秒钟才能打开活动,因此我在该代码下面使用了以下代码,该代码执行得很好,但滚动不流畅且耗时很多热门公开活动
答案 0 :(得分:1)
尝试一下,这可能会帮助
recyclerView.setNestedScrollingEnabled(false);