在android中创建自定义日历形状,如谷歌日历图像

在android中创建自定义日历形状,如谷歌日历图像,android,xml,android-layout,android-custom-view,Android,Xml,Android Layout,Android Custom View,我想创建自定义日历形状,如,并将其用作其他视图(如ImageView和Textview)的容器 我尝试使用XML可绘制形状,结果似乎不太好 我试图通过编程方式创建它,但我不知道如何在自定义视图中放置其他视图 正确的方法是什么 bg_calendar_view.xml bg_notification_view.xml bg_bottom_calendar.xml <layer-list xmlns:android="http://schemas.android.com/apk

我想创建自定义日历形状,如,并将其用作其他视图(如ImageView和Textview)的容器 我尝试使用XML可绘制形状,结果似乎不太好 我试图通过编程方式创建它,但我不知道如何在自定义视图中放置其他视图 正确的方法是什么

bg_calendar_view.xml


bg_notification_view.xml


bg_bottom_calendar.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:bottom="4dp"
    android:right="25dp"
    android:left="25dp"
    android:drawable="@drawable/bg_notification_view">

</item>
<item
    android:left="15dp"
    android:bottom="20dp"
    android:right="15dp"


    android:drawable="@drawable/bg_notification_view">


</item>
<item
    android:bottom="40dp"
    android:drawable="@drawable/bg_notification_view">

</item>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:bottom="4dp"
    android:right="25dp"
    android:left="25dp"
    android:drawable="@drawable/bg_calendar_view">

</item>
<item
    android:right="15dp"
    android:left="15dp"
    android:top="20dp"
    android:drawable="@drawable/bg_calendar_view">

</item>
<item
    android:top="40dp"
    android:drawable="@drawable/bg_calendar_view_blue">

</item>

bg_top_calendar.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:bottom="4dp"
    android:right="25dp"
    android:left="25dp"
    android:drawable="@drawable/bg_notification_view">

</item>
<item
    android:left="15dp"
    android:bottom="20dp"
    android:right="15dp"


    android:drawable="@drawable/bg_notification_view">


</item>
<item
    android:bottom="40dp"
    android:drawable="@drawable/bg_notification_view">

</item>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:bottom="4dp"
    android:right="25dp"
    android:left="25dp"
    android:drawable="@drawable/bg_calendar_view">

</item>
<item
    android:right="15dp"
    android:left="15dp"
    android:top="20dp"
    android:drawable="@drawable/bg_calendar_view">

</item>
<item
    android:top="40dp"
    android:drawable="@drawable/bg_calendar_view_blue">

</item>

my_layout.xml

<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"
android:padding="16dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:background="@drawable/bg_top_calendar"
    android:padding="40dp"
    android:gravity="center"
    android:orientation="vertical"
    >
    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/notification"
        android:layout_gravity="center"
        android:layout_marginBottom="8dp"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="you Have 31 Notification"
        android:textColor="@color/white"
        android:textSize="18sp"/>

</LinearLayout>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:background="@drawable/bg_bottom_calendar"
    android:paddingBottom="40dp"
    android:paddingStart="4dp"
    android:paddingEnd="4dp"
    android:paddingTop="4dp"
    >

</FrameLayout>


我们制定了几个月的日历

首先,我们使用线性布局来填充单元格。我们有35个单元格,每个单元格包含1个RelativeLayout和3个TextView。

然后我们以编程方式将视图填充到单元格中,这很容易,但结果却是一个非常缓慢的实现。 然后我们使用RecyclerView进行单元实现,但它的速度并没有大幅提高

一旦我们发现我们的瓶颈是填充复杂视图35次

然后我们遇到了一个关于自定义视图的问题。因此,经过大量研究,我们决定尝试一下自定义视图,瞧!它像魅力一样解决了我们滞后的问题

你也应该像我们一样尝试一下