簡體   English   中英

Android 日歷視圖 - 如何自定義日歷視圖以使其像 Google 日歷應用程序一樣?

[英]Android Calendar View - How to customize Calendar View to make it like Google Calendar App one?

在最近的Google Calendar App中,有一個可以下拉顯示的日歷,顯示的樣式是這樣的:

在此處輸入圖片說明

本來想給App建個這樣的Calendar,但是當我把android API CalendarView放到app上的時候,它的風格就大不一樣了:

在此處輸入圖片說明

所以,問題是我如何設計/自定義 CalendarView 以喜歡 Google Calendar App 中的那個?

另外,對於Google Calendar App的日歷,當一個粒子上有事件時,日期文本下會出現“小圓點”(如上圖Google Calendar圖片中的8月19日和21日)。 如何實現這樣的事情,當我有一個日期列表(不是 android 日歷的事件,只是一個日期列表)並想在日歷上的這些日期上標記一個點,就像谷歌日歷應用程序所做的那樣?

我想為應用程序構建這樣的日歷

您可以使用此庫來實現您想要的。

在最近的 Google Calendar App 中,它有一個可以下拉顯示的日歷

您可以使用動畫隱藏/顯示日歷視圖。

日期文本下會有“小點”

我已經使用這個庫實現了這一點,但您需要對其進行一些研究並對其進行修改。這是使用畫布來構建日歷視圖,您可以使用這些日期的 x、y 坐標在您的日期上添加圓圈。只需通過這個庫的日期並使用畫布的drawCircle()方法。

我找到了一個創建下拉視圖的項目,如Google calendar應用程序

使用這個:示例項目

這是使用CollapsingToolbarLayout在里面放置自定義日歷CollapsingToolbarLayout ,它在事件日期設置點也是谷歌日歷應用程序的副本

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stateListAnimator="@animator/ann"
        app:expanded="false"
        android:background="@android:color/white"
        app:layout_behavior=".MyAppBarBehavior"
        tools:targetApi="lollipop">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"
            app:statusBarScrim="?attr/colorPrimaryDark">

            <!--large view -->
            <com.example.GoogleCalendar.GooglecalenderView
                android:id="@+id/calander"
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:orientation="vertical"
                app:layout_collapseMode="pin"

                android:layout_marginTop="?attr/actionBarSize"
              >


            </com.example.GoogleCalendar.GooglecalenderView>

            <!--top toolbar-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:title="fkdl"
                app:contentInsetLeft="0dp"
                app:contentInsetStart="0dp"
                app:titleTextColor="@color/colorPrimaryDark"
                android:background="@android:color/white"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay">

                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:clickable="true"
                    android:focusable="true">

                    <View
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginTop="10dp"
                        android:id="@+id/backsupport"
                        android:background="?attr/selectableItemBackground"
                        android:clickable="true"
                        android:layout_marginBottom="10dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
                <TextView
                        android:id="@+id/monthname"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingTop="4dp"
                        android:paddingBottom="4dp"
                        android:fontFamily="@font/googlesans_regular"
                        android:text="June"
                        android:textColor="#464646"
                        android:textSize="20sp" />
                    <ImageView
                        android:id="@+id/arrowImageView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_arrow_drop_up_black_24dp"
                        app:layout_constraintLeft_toRightOf="@+id/monthname"
                        android:translationX="-5dp"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"
                        tools:ignore="ContentDescription,RtlHardcoded" />
                                 </android.support.constraint.ConstraintLayout>

            </android.support.v7.widget.Toolbar>
  </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <com.example.GoogleCalendar.MyRecyclerView
        android:id="@+id/nestedView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


</android.support.design.widget.CoordinatorLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM