2016-02-23 23 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