새로 고침 중에 SwipeRefreshLayout으로 조각을 전환하면 조각이 고정되지만 실제로는 여전히 작동합니다.
업데이트 : 제대로 작동한다고 생각했습니다. 그러나 몇 가지 테스트 후에도 여전히 문제가 있습니다.
그런 다음 더 간단한 버전을 만들어 정확히 무슨 일이 발생하는지 확인하고 분리해야 할 상쾌한 조각이 여전히 남아 있음을 알게됩니다. 또는 정확히 새로운 조각 위에 이전 조각의보기가 남아 있습니다 . 내 원래 앱의 RecyclerView의 배경이 투명하지 않기 때문에 이전에 말한 것이 나왔습니다.
업데이트 끝
다음 MainActivity과 같은 레이아웃이 있습니다.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout android:id="@+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent"
android:layout_gravity="start" tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
ContentView채우기 위해 사용하는 조각 @id/container은 다음과 같이 구성됩니다.
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/tweet_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_300"/>
</android.support.v4.widget.SwipeRefreshLayout>
그리고 여기 onCreateView()에ContentView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View inflatedView = inflater.inflate(R.layout.fragment_content, container, false);
mRecyclerView = (RecyclerView) inflatedView.findViewById(R.id.tweet_list);
mRecyclerView.setHasFixedSize(false);
mLinearLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mTweetList = new ArrayList<Tweet>;
mAdapter = new TweetAdapter(mTweetList);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mSwipeRefreshLayout = (SwipeRefreshLayout) inflatedView.findViewById(R.id.contentView);
mSwipeRefreshLayout.setOnRefreshListener(
...
);
return inflatedView;
}
그런 다음 MainActivity다른 전환하여 표시 할 내용을 전환합니다 ContentView. 한 가지만 제외하면 모두보기 좋습니다. ContentView탐색 창에서 새로 고치는 동안 조각을 전환하면 콘텐츠가 멈 춥니 다. 그러나 실제로는 볼 수없는 것을 제외하고는 모든 것이 평소대로 작동합니다.
글쎄 ... 약간의 고군분투 끝에 결국 난이 문제를 혼자서 까다로운 방법으로 해결했다 ...
다음을 추가하면됩니다 onPause().
@Override
public void onPause() {
super.onPause();
...
if (mSwipeRefreshLayout!=null) {
mSwipeRefreshLayout.setRefreshing(false);
mSwipeRefreshLayout.destroyDrawingCache();
mSwipeRefreshLayout.clearAnimation();
}
}
이 문제는 appcompat 22.1.1에서 여전히 발생하는 것 같습니다. FrameLayout 내부에 SwipeRefreshLayout을 래핑하면이 문제가 해결되었습니다.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/tweet_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_300" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
@ zlm2012 답변 외에도이 문제가 지원 라이브러리 21.0.0에서 재현되었지만 현재 21.0.3에서 수정 된 것 같습니다.
솔루션은 작동하지만 다음과 같이 해당 행을 자체 기능에 넣는 것이 더 낫다고 생각합니다.
public void terminateRefreshing() {
mSwipeRefreshLayout.setRefreshing(false);
mSwipeRefreshLayout.destroyDrawingCache();
mSwipeRefreshLayout.clearAnimation();
}
조각을 전환 할 때 호출합니다.
Fragment prevFrag = fragmentManager.findFragmentById(drawerContainerId);
if(prevFrag instanceof SwipeRefreshFragment) {
((SwipeRefreshFragment)prevFrag).terminateRefreshing();
}
fragmentManager.beginTransaction().replace(drawerContainerId, fragment).commit();
It works! Just remove the transition from your fragment replacement, in my case I removed the following from my code:
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
Set clickable="true" in top parent layout... It may solve the problem.
For the time being, you can avoid the issue by:
public class FixedRefreshLayout extends SwipeRefreshLayout {
private static final String TAG = "RefreshTag";
private boolean selfCancelled = false;
public FixedRefreshLayout(Context context) {
super(context);
}
public FixedRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected Parcelable onSaveInstanceState()
{
if(isRefreshing()) {
clearAnimation();
setRefreshing(false);
selfCancelled = true;
Log.d(TAG, "For hide refreshing");
}
return super.onSaveInstanceState();
}
@Override
public void setRefreshing(boolean refreshing) {
super.setRefreshing(refreshing);
selfCancelled = false;
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
if(hasWindowFocus && selfCancelled) {
setRefreshing(true);
Log.d(TAG, "Force show refreshing");
}
}
}
This has the added advantage of resuming the animation incase you decide to not switch the fragment (coming from some menu). It also ties in with the internal animation to make sure that the refreshing animation does not return if the network refresh has already completed.
Terminate SwipeRefresh whenever navigation menu item is clicked. It worked.
private void selectItem(int position) {
mSwipeRefreshLayout.setRefreshing(false);
/*
Other part of the function
*/
}
'Program Club' 카테고리의 다른 글
| Atom 편집기에서 * pyc 파일을 숨기는 방법 (0) | 2020.10.25 |
|---|---|
| Android Studio를 사용하여 메모리를 분석하는 방법 (0) | 2020.10.25 |
| 해결 실패 : com.google.firebase : firebase-core : 11.2.0 (0) | 2020.10.25 |
| 이진 트리 vs. 연결 목록 vs. 해시 테이블 (0) | 2020.10.25 |
| jQuery 시간 선택기 (0) | 2020.10.25 |