I am using CalendarView within ScrollView. The minimum SDK is 17, the target sdk is 25, compile sdk 25, and build-tools version 25.0.3. The problem I experienced is with scrolling. Running this on devices API v23 and higher appears to work OK, but for lower API's when the ScrollView is required to activate, it is not possible to scroll the calendar to another month.
From what I have viewed, it appears that this may have been fixed in API v23 by making the Calendar scroll horizontally while the ScrollView scrolls vertically. Using a device with v22, they both scroll vertically and therefore the scroll of the CalendarView to another month does not work when the ScrollView is required to activate. At least that's what it appears to me to be.
In my efforts to find a fix for this, it appears that the answer provided by user @Joel in the following post fixes this by providing a custom ScrollView:
HorizontalScrollView within ScrollView Touch Handling
I'm very surprised that after all this time that it hasn't been fixed by the Android team in v22 and prior. The original fix was posted by the above user on 16-Apr-2010.
While I'm pleased that this has been fixed by the above SO post, is there another native way to fix this? My only real concern is that the custom ScrollView may not provide a solution for all possible cases. I've only implemented the custom ScrollView for API v22 and lower and for API v23 and higher I use the native ScrollView.
Edit: Example added as requested. OK in v23 and above However, in v22 emulator Landscape cannot change month
package boh3.com.testcal001;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity;
public class ActivityMain extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/colorPrimary"
app:tabGravity="fill"
app:tabMode="fixed" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lay_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tabs"
android:orientation="vertical">
<!-- Selected Date -->
<TextView
android:id="@+id/txv_date_and_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:lines="1"
android:padding="4dip"
android:text="This is Some Text"
android:textSize="18sp"
android:textStyle="bold" />
<!-- TIME UNTIL DATE AND TIME -->
<TextView
android:id="@+id/txv_remaining_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txv_date_and_time"
android:gravity="center_horizontal"
android:lines="1"
android:padding="4dip"
android:text="This is some more text"
android:textColor="@color/colorAccent"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lay_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lay_detail"
android:layout_marginBottom="65dip"
android:layout_marginTop="10dip"
android:orientation="vertical">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/lay_fragment"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_gravity="top|center"
android:layout_marginBottom="0dip"
android:layout_marginTop="0dip"
android:layout_weight="1"
android:orientation="vertical">
<CalendarView
android:id="@+id/date_picker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:layout_marginBottom="25dip"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:orientation="horizontal"
android:textSize="12sp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true"
/>