2016-02-23 21 views
0

我有一个跳帧的问题,在一个真正的设备上,大约90-110帧,但在模拟器上它只有20-30。 我有这个问题,因为我有一个活动内的5个片段,每个片段都有15到30个按钮,它们是LinearLayouts,因为我需要在一个按钮中放置两个图片和TextView,这似乎是一种方法。Android - 用加载动画替换跳过的框架

这就是它跳过帧的原因,我需要等待几秒钟才能打开活动。

这看起来不太好,因为碎片中的数据量不足,我决定创建加载动画。

但问题是,无论何时创建它,遵循YouTube或StackOverflow上的各种教程,只有在活动打开时才会出现加载动画,然后就没有用处。

有谁知道解决方案?

活动XML

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="hr.app.liftme.liftmehr.Vjezbe"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     android:elevation="0dp" 
     app:elevation="0dp"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.AppBarOverlay" /> 

    </android.support.design.widget.AppBarLayout> 
    <include layout="@layout/content_vjezbe" /> 



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

内容的XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:elevation="0dp" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="hr.app.liftme.liftmehr.Vjezbe" 
    tools:showIn="@layout/activity_vjezbe" 
    android:id="@+id/loadingPanel"> 


    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:text="Vježbe" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 


     <android.support.design.widget.TabLayout 
      android:id="@+id/tabLayout" 
      app:tabMode="scrollable" 
      app:tabGravity="fill" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 


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

     <android.support.v4.view.ViewPager 

      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/viewPager" 
      android:background="#ffffff"> 

     </android.support.v4.view.ViewPager> 

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

</LinearLayout> 

回答

0

您可以在您的XML中插入布局(例如具有背景颜色和微调器的RelativeLayout),该布局将占用所有屏幕大小。当您完成加载碎片时,将该布局的可见性设置为Gone

+0

对不起,我是Android的新手,你可以一步一步走过我吗?我用RelativeLayout作为根元素创建新的布局资源文件?然后设置背景颜色并将其中的进度条?或者一些自定义的微调?那又怎么样? – DaxHR

+0

发布您的活动的XML –

+0

它在第一篇文章中 – DaxHR