【发布时间】:2016-08-25 16:55:08
【问题描述】:
我创建了一个带有滚动视图的活动,其中包含几个按钮和文本视图。在我将 DatePicker 添加到我的滚动视图之前,FPS 可以保持 60fps。但我不明白为什么当我添加 DatePicker 时 FPS 会急剧下降。而且我还没有发现其他小部件的性能如此糟糕。
为什么我担心这个 DatePicker 的性能? 因为我想在带有弹出动画的弹出窗口中显示这个 DatePicker。由于 DatePicker 的性能不佳,动画一直在抖动。我真的很想改进它。皮斯给我一些暗示。
这是我添加了 DatePicker 的 xml 文件。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/common_white"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test_db" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/backup_database"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="backup_database" />
<Button
android:id="@+id/restore_database"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="restore_database" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/test_result"
android:text="hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<DatePicker
android:id="@+id/test_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"></DatePicker>
</LinearLayout>
</ScrollView>
</LinearLayout>
这是我如何初始化 DatePicker
Calendar today = Calendar.getInstance();
int year = today.get(Calendar.YEAR);
int month = today.get(Calendar.MONTH) + 1;
int day = today.get(Calendar.DAY_OF_YEAR);
DatePicker picker = (DatePicker) findViewById(R.id.test_picker);
picker.setCalendarViewShown(false);
picker.updateDate(year, month, day);
没有 DatePicker 的 GPU 渲染配置文件超过 60FPS(由于声誉不足,我无法发布此图片) DatePicker 小于 60FPS 的 GPU 渲染配置文件
GPU rendering profile with DatePicker less than 60FPS
用DatePicker进行层次视图分析,测量1ms以上,绘制15ms以上,当然达不到60FPS。
Hierarchy View analysis with DatePicker
而且我认为我的手机并没有那么慢,因为在运行支持 v7 示例的 Palette 示例时它可以轻松获得 60 FPS,该示例包含许多文本视图和图像视图。这是截图。(由于信誉不足,我无法发布此图片)
【问题讨论】:
标签: android datepicker android-widget android-animation