gpt4 book ai didi

java - Android 日历布局

转载 作者:太空宇宙 更新时间:2023-11-04 14:35:06 24 4
gpt4 key购买 nike

我的日历布局如下所示:

A B C D E F G

A B C D E F G

A B C D E F G

A B C D

我想让日历的第一天开始,例如,从第四个元素的位置开始(此实现应该仅适用于日历的第一行),如下所示:

 blank A B C D

A B C D E F

A B C D E F

A B C D E F

我为此有一个 GridView,它使用一个带有 Button 的relativelayout,该按钮具有另一个布局作为背景,但现在不应该相关。

有什么建议吗...?谢谢:)

最佳答案

在通知您数据集更改之前,您可以使用此功能。

public void refreshDays() {
// clear items
items.clear();
flagDepartureDate = false;
flagArrivalDate = false;

int lastDay = month.getActualMaximum(Calendar.DAY_OF_MONTH);
int firstDay = month.get(Calendar.DAY_OF_WEEK);

Calendar temp = (Calendar) month.clone();
temp.add(Calendar.MONTH, -1);

Calendar temp2 = (Calendar) month.clone();
temp2.add(Calendar.MONTH, +1);

int lastDay_prev = temp.getActualMaximum(Calendar.DAY_OF_MONTH);

/*
* if(((firstDay-1)+lastDay)>35) {
*/
calDay.days = new String[42];
calDay.month = new int[42];
calDay.year = new int[42];
/*
* } else{ calDay.days = new String[35]; calDay.month = new int[35];
* calDay.year = new int[35]; }
*/

// Log.i("LAST DAY", lastDay+"");
// Log.i("LAST DAY PREV", lastDay_prev+"");
// Log.i("FIRST DAY", firstDay+"");
// Log.i("FIRST_DAY_OF_WEEK", FIRST_DAY_OF_WEEK+"");
int start_blanks = 0;
int j = FIRST_DAY_OF_WEEK;

// populate empty days before first real day
if (firstDay > 1) {
for (j = 0; j < firstDay - FIRST_DAY_OF_WEEK - 1; j++) {

calDay.days[j] = ""
+ (lastDay_prev - (firstDay - FIRST_DAY_OF_WEEK - 1)
+ j + 1);
calDay.month[j] = temp.get(Calendar.MONTH);
calDay.year[j] = temp.get(Calendar.YEAR);
start_blanks += 1;
}
} else {
for (j = 0; j < FIRST_DAY_OF_WEEK * 6; j++) {
calDay.days[j] = "";
}
j = FIRST_DAY_OF_WEEK * 6; // sunday => 1, monday => 7
}
// Log.i("START_BLANK", start_blanks+"");
// populate days
int dayNumber = 1;
for (int i = j; i < (lastDay + start_blanks); i++) {
calDay.days[i] = "" + dayNumber;
calDay.month[i] = month.get(Calendar.MONTH);
calDay.year[i] = month.get(Calendar.YEAR);
dayNumber++;
}

// populate empty days before first real day
for (int i = (lastDay + start_blanks), k = 1; i < calDay.days.length; i++, k++) {
calDay.days[i] = "" + k;
calDay.month[i] = temp2.get(Calendar.MONTH);
calDay.year[i] = temp2.get(Calendar.YEAR);
}

}

这里的“月”是当前日历月的对象

关于java - Android 日历布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25683942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com