だから、私は私のアプリでは、この奇妙なことになってきました。
このことを考えてみましょう、私が持っているAppCompatActivity
持っている、ViewPager
二つの断片を含む、その中。私が追加したLottieAnimationView
フラグメントの両方の内側。
ではFragmentA
私が使用してサーバーからデータをフェッチしていRetrofit
て、負荷に、それが非表示になりますLottieAnimationView
。でFragmentB
(のみ間違っているものをチェックするためのものである)、私は使用していますHandler
非表示にするにはLottieAnimationView
3秒後。
今、私はアプリを最小化し、再度それを開くたびに、私は見LottieAnimationView
IことsetVisibility(View.GONE)
でのみFragmentA
。でFragmentB
たとき、私は、私はビューが表示されないsetVisibility(View.GONE)
(期待どおりに動作する)、再びアプリを最小化し、開いた後。
ここで私が見るもののイメージですFragmentA
。
LottieAnimationView
一時停止状態になっています。
ここに私のコードですFragmentA
。
public class FragmentA extends Fragment {
private AdapterEventStore mAdapter;
private List<Item> mStore;
private final String hostName = "https://xxx.xxx.xxx";
private View view;
private Context context;
private LottieAnimationView lottieAnimationView;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_a, container, false);
context = view.getContext();
lottieAnimationView = view.findViewById(R.id.ais_lav_loading);
lottieAnimationView.setVisibility(View.VISIBLE);
initRecyclerView();
return view;
}
private void initRecyclerView() {
RecyclerView store = view.findViewById(R.id.ais_rv_event_store);
store.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
mStore = new ArrayList<>();
mAdapter = new AdapterEventStore(context, mStore);
store.setAdapter(mAdapter);
fetchDataFromServer();
}
private void fetchDataFromServer() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
final Retrofit retrofit = new Retrofit.Builder()
.client(httpClient.build())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(hostName)
.build();
APIGetItem itemShop = retrofit.create(APIGetItem.class);
Call<ModelEventExclusive> call = itemShop.getEventStore(hostName);
call.enqueue(new Callback<ModelEventExclusive>() {
@Override
public void onResponse(Call<ModelEventExclusive> call, Response<ModelEventExclusive> response) {
Log.e("Response: ", response.body().getItems().get(0).getItemName());
mEventStore.addAll(response.body().getItems());
mAdapter.notifyDataSetChanged();
hideLottieAnimation();
}
@Override
public void onFailure(Call<ModelEventExclusive> call, Throwable t) {
hideLottieAnimation();
Toast.makeText(context, "Error:"+t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
Log.e("Error occurred: ", t.getMessage());
}
});
}
private void hideLottieAnimation(){
lottieAnimationView.cancelAnimation();
lottieAnimationView.setVisibility(View.GONE);
}
}
レイアウトのための FragmentA
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ais_rv_event_store"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/ais_lav_loading"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
app:lottie_autoPlay="true"
app:lottie_loop="true"
android:visibility="gone"
app:lottie_repeatMode="reverse"
app:lottie_rawRes="@raw/loading" />
</FrameLayout>
可視性があることに注意してくださいLottieAnimationView
に設定されているGONE
最初に。アイテム100%の作品をフェッチする上記のコード私は実際の変数/クラス名を隠そうに悪い仕事をしてきたように、構文/変数名に誤りを指摘しないでください。
ここでは、コードにです FragmentB
public class FragmentB extends Fragment {
private LottieAnimationView anim_loading;
private View view;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_b, container, false);
anim_loading = view.findViewById(R.id.lav_loading);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
anim_loading.cancelAnimation();
anim_loading.setVisibility(View.GONE);
}
}, 3000);
return view;
}
}
あなたは私がここで間違ってやって教えていただけますか?なぜそれが一つの断片で期待どおりに動作し、他にはないのですか?それは私がレトロフィットコールバックの内側にそれを隠していますどのようにして何もする必要はありますか?
フォームの背景を取得するときに問題があるonResume
あなたがでビューを非表示にする行を追加する必要があるので、呼び出されますonResume
、ではありませんonCreateView
チェックこの詳細についてはアウト