私は、フラグメント遷移中に適切な進行スピナーを実装するためにさまざまな方法を試してきました。このような何か:不確定スピナーを実装するためのベストプラクティス
私が遭遇していますメイン、包括的な問題はスピナーが消えると(スピナーの)背景を透明になったとき、古いフラグメントがまだ表示されていることです。私は幸運にいくつかのことを試して、私はオプションがなくなったように感じる。もし誰かがきれいにこれを行う方法を知っている方法を持っている、私に知らせてください。また、私は私がDrawerLayoutを使用しています代わりにreplace
の断片のためのadd
を使用しています方法を維持したい、とここに私のレイアウト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>
私が試してみましたこの:
RelativeLayout
にProgressBar
を置き、必要に応じて表示のオンとバックグラウンドを色に設定し、表示をオフにしてバックグラウンドを透明にする。拡張されたフラグメントクラスの外で行った。拡張フラグメントクラス内で同じですが、ここでは2つの異なる方法を試してみました。 1つの試みで、私は
onViewCreated
のアイテムを隠し、もう1つは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);
}
}