2016-04-30 23 views
0

我已经用ctrlView打包了一个包含几个按钮和文字浏览的活动。在将DatePicker添加到我的scrollView之前,FPS可以保持60fps。但我不明白为什么当我添加DatePicker时,FPS会急剧下降。而且我还没有发现其他widget有这样糟糕的表现。由于性能差,android datepicker动画打架

为什么我关心这个DatePicker的性能? 因为我想用弹出动画在弹出窗口中显示此DatePicker。由于DatePicker的糟糕表现,动画一直在抽动。我真的想改善它。皮斯给我一些提示。

这是我的xml文件,我添加了DatePicker。

<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); 

GPU渲染没有的DatePicker超过60FPS的个人资料(我不能发布这张照片的,因为短期声誉) GPU渲染轮廓具有的DatePicker低于60FPS

GPU rendering profile with DatePicker less than 60FPS

与DatePicker的层次视图分析,测量1ms以上,绘制超过15毫秒,当然它不能达到60FPS。

Hierarchy View analysis with DatePicker

而且我觉得我的手机是不慢,因为从运行支持V7例如调色板例子拥有许多textviews和imageviews当它可以很容易地得到了60 FPS。下面是截图。(我不能发布,因为短声誉的这张照片)

回答

0

这里说到我自己

的解决方案。它是衰落的边缘效应减慢日期选取器的性能。详细信息,请参阅

Why are fading edges slow?

http://www.curious-creature.com/2008/12/22/why-is-my-list-black-an-android-optimization/

对于使用日期选取具有良好的性能,只需禁用衰落边缘效应会工作。

android:fadingEdge="none" 

对于其他允许淡化边缘效果的控件,它会减慢绘制过程。

如何使自己的自定义淡入淡出效果?

在自己的视图中绘制一个衰落的边缘绘制这样的:

private final PaintDrawable mGradientDrawable; 
private final ShapeDrawable.ShaderFactory mShaderFactory; 

mShaderFactory = new ShapeDrawable.ShaderFactory() { 
    @Override 
    public Shader resize(int width, int height) { 
     LinearGradient lg = new LinearGradient(0, 0, 0, height, 
       new int[]{ 
         0xffffffff, 
         0x00ffffff, 
         0x00ffffff, 
         0xffffffff,}, 
       new float[]{0, 0.3f, 0.5f, 1}, 
       Shader.TileMode.REPEAT); 
     return lg; 
    } 
}; 
mGradientDrawable = new PaintDrawable(); 
mGradientDrawable.setShape(new RectShape()); 
mGradientDrawable.setShaderFactory(mShaderFactory); 

的绘制将创建一个从白色到透明的渐变。