android - CalendarView 需要很多时间来显示

标签 android android-calendar

我正在开发 CalendarView 上的应用程序。 我必须以小型线性布局显示 calendarView。

在以小型线性布局显示包含 calendarView 的整个页面时出现问题。 -> 这需要 10 秒才能显示,而且时间很长...

布局中没有其他东西。

这是我的 xml 和 snap...

我们将强烈感谢任何帮助...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="30"
                android:paddingLeft="30dp" >

                <TextView
                    android:id="@+id/txtDate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="My Calendar"
                    android:textSize="50sp" />

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="2dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="40dp"
                    android:layout_marginRight="30dp"
                    android:background="@android:color/black" />
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="70"
                android:paddingBottom="30dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingTop="30dp" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:orientation="vertical" >

                    <ListView
                        android:id="@+id/list_task"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content" >
                    </ListView>
                </LinearLayout>
            </RelativeLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="30" >

                <CalendarView
                    android:id="@+id/cal_small"
                    android:layout_width="250dp"
                    android:layout_height="250dp"
                    android:layout_centerHorizontal="true"
                    android:background="@android:color/darker_gray"
                    android:showWeekNumber="false"
                    android:animateLayoutChanges="false"
                    android:clipChildren="false"
                    android:drawingCacheQuality="low"
                    android:soundEffectsEnabled="false"
                    android:hapticFeedbackEnabled="false"
                     />

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="2dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="40dp"
                    android:layout_marginLeft="30dp"
                    android:layout_marginRight="30dp"
                    android:background="@android:color/black" />
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="70" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_marginBottom="30dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginTop="30dp"
                    android:orientation="vertical" >

                    <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="0dp"
                        android:layout_weight="8" >

                        <ListView
                            android:id="@+id/list1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:paddingLeft="30dp" >
                        </ListView>
                    </LinearLayout>

                    <ListView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" >
                    </ListView>
                </LinearLayout>
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

enter image description here

最佳答案

这看起来很简单,但我不小心测试了这个,而且效果很好。我希望这对您也有帮助...

首先创建单独的 xml 文件,其中只包含 CalendarView。命名为“cal_view.xml”

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.widget.CalendarView
        android:layout_width="200dp"
        android:layout_height="200dp" />

</LinearLayout> 

然后将这个 xml 文件包含到您的主 xml 文件中,就像下面这样。 代替您的 CalanderView,包含 xml 文件。

 <include
     android:id="@+id/subCategory"
     layout="@layout/cal_view" />

关于android - CalendarView 需要很多时间来显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18721298/

相关文章:

Android导航组件: PopEnterAnim not working

android - Android 日历事件的 BroadcastReceiver

Android 日历 View ,仅显示 2 周

android - 将 HARD CODE 值设置为日历实例后出现空指针异常

android - 日历事件保存在手机本地,但无法同步到 Google 日历

android - 如何以手机音量而非扬声器音量播放音频文件

android - Flutter - 使用 Agora 的来电功能

java - Android 应用程序中 Iframe 站点的进度状态

java - 无法在谷歌地图上自动显示当前位置?

android - 如何自动将事件添加到日历?