Comments (12)
Hmm it shows up again after I click on a day.
from calendar.
Can you share the calendar setup which reproduces this issue? The calendar config in XML and initialization code should be sufficient.
from calendar.
XML:
<com.kizitonwose.calendarview.CalendarView
android:id="@+id/calendar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/calendar_month_year_text"
android:layout_marginTop="6dp"
app:cv_dayViewResource="@layout/item_calendar_day"
app:cv_monthHeaderResource="@layout/item_calendar_header"
app:cv_orientation="horizontal"
app:cv_outDateStyle="endOfRow"
app:cv_scrollMode="paged"/>
Kotlin:
`private var selectedDate: LocalDate? = null
private val monthTitleFormatter = DateTimeFormatter.ofPattern("MMMM")
private val cal by bind(R.id.calendar)
private val monthYear by bind(R.id.calendar_month_year_text)
private val back by bind(R.id.calendar_previous)
private val next by bind(R.id.calendar_next)
override fun bindView(itemView: View) {
super.bindView(itemView)
val daysOfWeek = daysOfWeekFromLocale()
val currentMonth = YearMonth.now()
cal.setup(currentMonth.minusMonths(10), currentMonth.plusMonths(10), daysOfWeek.first())
cal.scrollToMonth(currentMonth)
cal.dayBinder = this
cal.monthScrollListener = this
back.setOnClickListener(this)
next.setOnClickListener(this)
cal.monthHeaderBinder = object : MonthHeaderFooterBinder<MonthViewContainer> {
override fun create(view: View) = MonthViewContainer(view)
override fun bind(container: MonthViewContainer, month: CalendarMonth) {
// Setup each header day text if we have not done that already.
if (container.legendLayout.tag == null) {
container.legendLayout.tag = month.yearMonth
container.legendLayout.children.map { it as TextView }.forEachIndexed { index, tv ->
tv.text = daysOfWeek[index].name.take(1)
}
}
}
}
}
override fun create(view: View): DayViewContainer = DayViewContainer(view)
override fun bind(container: DayViewContainer, day: CalendarDay) {
container.day = day
container.view.text_calendar_day.text = day.date.dayOfMonth.toString()
if (day.owner == DayOwner.THIS_MONTH) {
container.view.text_calendar_day.setTextColorRes(R.color.silver_c8)
container.view.layout_calendar_day.setBackgroundResource(if (selectedDate == day.date) R.drawable.background_circle else 0)
container.view.dot_calendar_day.imageTintList = ColorStateList.valueOf(view.context.getColorCompat(R.color.silver_c8))
} else {
container.view.text_calendar_day.setTextColorRes(R.color.silver_c8_o35)
container.view.layout_calendar_day.background = null
container.view.dot_calendar_day.imageTintList = ColorStateList.valueOf(view.context.getColorCompat(R.color.silver_c8_o35))
}
}
override fun invoke(month: CalendarMonth) {
val title = "${monthTitleFormatter.format(month.yearMonth)} ${month.yearMonth.year}"
monthYear.text = title
selectedDate?.let {
// Clear selection if we scroll to a new month.
selectedDate = null
cal.notifyDateChanged(it)
}
}
override fun onClick(v: View) {
when (v.id) {
R.id.calendar_previous -> (cal.findFirstCompletelyVisibleMonth() ?: cal.findFirstVisibleMonth())?.let { cal.smoothScrollToMonth(it.previous.yearMonth) }
R.id.calendar_next -> (cal.findFirstCompletelyVisibleMonth() ?: cal.findFirstVisibleMonth())?.let { cal.smoothScrollToMonth(it.next.yearMonth) }
}
}
inner class MonthViewContainer(view: View) : ViewContainer(view) {
val legendLayout = view.legendLayout
}
inner class DayViewContainer(view: View) : ViewContainer(view), View.OnClickListener {
lateinit var day: CalendarDay // Will be set when this container is bound.
init {
view.setOnClickListener(this)
}
override fun onClick(v: View) {
if (day.owner == DayOwner.THIS_MONTH) {
if (selectedDate != day.date) {
val oldDate = selectedDate
selectedDate = day.date
cal.notifyDateChanged(day.date)
oldDate?.let { cal.notifyDateChanged(it) }
}
}
}
}`
from calendar.
And as I said, click on a date makes it reappear, probably because of notifyDateChanged call.
from calendar.
Could you please share @layout/item_calendar_day
and @layout/item_calendar_header
?
from calendar.
item_calendar_day:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_calendar_day"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="1dp">
<TextView
android:id="@+id/text_calendar_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_gravity="center"
tools:text="24"
android:textSize="16sp"
android:textColor="@color/silver_c8"
android:letterSpacing="-0.01"/>
<ImageView
android:id="@+id/dot_calendar_day"
android:src="@drawable/background_white_round"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="8dp"
android:layout_width="4dp"
android:layout_height="4dp"/>
</FrameLayout>
item_calendar_header:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/legendLayout"
android:layout_width="match_parent"
android:layout_height="20dp"
android:gravity="center"
android:background="#0cffffff"
android:orientation="horizontal"
tools:ignore="HardcodedText">
<TextView
android:id="@+id/legendText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:includeFontPadding="false"
android:textSize="12sp"
android:textColor="@color/silver_c8"/>
<TextView
android:id="@+id/legendText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_weight="1"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/silver_c8"/>
<TextView
android:id="@+id/legendText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_weight="1"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/silver_c8"/>
<TextView
android:id="@+id/legendText4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_weight="1"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/silver_c8"/>
<TextView
android:id="@+id/legendText5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_weight="1"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/silver_c8"/>
<TextView
android:id="@+id/legendText6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_weight="1"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/silver_c8"/>
<TextView
android:id="@+id/legendText7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:layout_weight="1"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/silver_c8"/>
</LinearLayout>
from calendar.
Same issue here
from calendar.
This is now fixed in version 0.1.2
This was happening because ViewGroups clip their children by default, hence the last row which is outside the CalendarView's bounds is not drawn when the calendar moves from a month with 5 rows to one with 6 rows.
from calendar.
@kizitonwose Thanks you for your fix!!
But now it takes time for the 6th row to appear in case we move from month with 5 rows.
from calendar.
But now it takes time for the 6th row to appear in case we move from month with 5 rows.
This is because the CalendarView's height is set to wrap_content
, hence, it has to adjust its height to match the current month when it moves to a new month. You should set the height to match_parent
if you don't want this behavior.
from calendar.
Maybe caching the last and next months will solve this issue?
@kizitonwose
from calendar.
The months are cached. This is the expected behavior when a view wraps its content. If the calendar view does not resize, then months with 5 rows will show an empty last row.
See the screenshot below:
from calendar.
Related Issues (20)
- How can I add my logic to the month change event HOT 2
- The calendar day started on Monday, but it should begin on Sunday (version 2.1.1). HOT 1
- OOM: Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 1101856 free bytes and 1076KB until OOM, target footprint 201326592, growth limit 201326592; failed due to fragmentation (largest possible contiguous allocation 32768000 bytes) HOT 2
- Throw AbstractMethodError: abstract method "float androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider.calculateSnappingOffset(float) when scrolling calendar HOT 8
- Some calendar month days do not appear when I scroll the calendar vertically HOT 2
- collapse the monthly view into a weekly view HOT 4
- java.lang.IllegalArgumentException: The initial value must have an associated anchor. HOT 9
- Fast Scrolling HOT 2
- Stable calendar height during scroll HOT 4
- Can you compose example6 be written in view HOT 1
- FirstDayOfMonth with out and in dates HOT 5
- How make such calendar? (screenshot below) HOT 3
- Multiplatform support HOT 8
- Swiping on Calendar composable results in crash with following exception "java.lang.AbstractMethodError: abstract method "float androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider.calculateApproachOffset(float)"" HOT 2
- Horizontal Calendar crashing HOT 5
- Yearly calendar view HOT 2
- Changing `firstDayOfWeek` on `CalendarState` in Compose module doesn't refresh the current month HOT 3
- Displaying Calendar for Weekdays Only HOT 9
- How to set the week titles from Monday to Sunday. HOT 1
- How to do swipe up to change to week view and swipe down to change month view for Compose Calendar HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from calendar.