2017-05-09 22 views
0

我一直在嘗試很多不同的方法來實現在片段轉換過程中適當的進度微調框。事情是這樣的:實現不確定微調框的最佳實踐

enter image description here

,我遇到的主要,首要的問題是,當微調消失,(旋轉的)背景變透明仍在顯示舊片段。我嘗試了一些不幸的事情,而且我覺得我已經沒有選擇餘地了。如果任何人有辦法,他們知道如何幹淨地做到這一點,請讓我知道。我也想保持我使用add的片段,而不是replace我使用的是DrawerLayout的方式,這是我的佈局XML:

<android.support.v4.widget.DrawerLayout 
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:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<FrameLayout 
    android:id="@+id/main_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.citychurchtulsa.cc.citychurchapp.MainActivity"/> 

<!--Only holds progress bar, main container will be for fragment display!!!--> 
<RelativeLayout 
    android:id="@+id/relative_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center"> 

    <ViewStub 
     android:id="@+id/loadSpinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inflatedId="@+id/subView" 
     android:layout="@layout/progress_spinner"/> 

</RelativeLayout> 


<!-- Side navigation drawer UI --> 
<ExpandableListView 
    android:id="@+id/nav_view" 
    android:layout_width="@dimen/nav_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="left|start" 
    android:background="@color/white" 
    android:divider="@color/colorPrimary" 
    android:dividerHeight="@dimen/divider_height" 
    android:groupIndicator="@android:color/transparent" 
    android:indicatorLeft="? 
android:attr/expandableListPreferredItemIndicatorLeft"/> 

</android.support.v4.widget.DrawerLayout> 

這是我曾嘗試:

  • ProgressBar放在RelativeLayout中,然後在需要時將背景設置爲和RelativeLayout背景設置爲某種顏色,並在我不需要時關閉背景和將背景設置爲透明。在擴展片段類外部完成。

  • 同上,但是在擴展片段類中完成。在這裏嘗試了兩種不同的方法。在一次嘗試中,我將項目隱藏在onViewCreated中,另一項隱藏在onStart中。

  • 創建我用,就像我承諾就像我的其他片段,然後回去通過所需的片段

  • 使用postDelayed處理程序提交一個空的片段,但我不一定喜歡既然所有設備都不同

不管怎樣,我覺得我已經嘗試更多,但我的頭頂部,我想不出別的。我非常感謝任何幫助。

這裏是我的顯示/隱藏微調的代碼,我一直在嘗試使用:

public void enableLoadSpinner(boolean set){ 
    if(set) 
    { 
     mainContainer.setVisibility(View.GONE); 
     loadSpinner.setVisibility(View.VISIBLE); 
     relativeLayout.setBackgroundResource(R.color.colorSecondary); 
    } 
    else 
    { 
     mainContainer.setVisibility(View.VISIBLE); 
     loadSpinner.setVisibility(View.GONE); 
     relativeLayout.setBackgroundResource(android.R.color.transparent); 
    } 
} 

回答

0

好吧,我想通了這個問題!關於ProgressBarFragmentTransaction的觀點存在問題!!!兩者之間發生了某種奇怪的交互,所以我刪除了FragmentTransaction,並使用自定義動畫使ProgressBar消失。