我有一个包含一个包含Recycler视图的刷卡刷新布局的片段,我添加了自定义转换,并在我开始片段的事务之前通过frag.setEnterTransition()
将其与片段相关联。但是它根本没有转变。它突然出现,就像它没有过渡一样。
为了缩小我可能出错的地方,我用LinearLayout
而不是swipeRefreshLayout
重新设置它,并且片段按预期转换。
这是片段的xml。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_refresh_layout_inapp_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rv_inapp_messages_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="@dimen/transactions_space_small"/>
<include layout="@layout/widget_empty_screen"/>
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
这就是片段的交易方式。
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
fragment.setEnterTransition(bottomGravitySlide);
fragment.setExitTransition(fadeOut);
fragment.setAllowEnterTransitionOverlap(false);
fragment.setAllowReturnTransitionOverlap(false);
}
fragmentTransaction.replace(R.id.vg_full_container, fragment, TAG_INTRODUCTION).commitAllowingStateLoss();
我正在使用API23,因此API检查应该不是问题。
我哪里错了?如果我想使用swipeRefreshLayout并且仍然能够转换,我该怎么办?
答案 0 :(得分:0)
我想通过在SwipeRefreshLayout中进行过渡来以编程方式将浮动操作按钮移到顶部中心,并且遇到了相同的问题。
用FrameLayout封装SwipeRefreshLayout解决了我的问题。
之前:
onCreate()
之后:
progressBar = findViewById(R.id.progress);
webView = findViewById(R.id.web_view);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
// Keep WebView hidden when the url is loading
webView.setVisibility(View.INVISIBLE);
// Make ProgressBar visible
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
progressBar.incrementProgressBy(newProgress);
if(newProgress == 100 && progressBar.getVisibility() == View.VISIBLE) {
// Make ProgressBar invisible and WebView visible
progressBar.setVisibility(View.INVISIBLE);
webView.setVisibility(View.VISIBLE);
}
});
webView.loadUrl(URL);