![](/img/trans.png)
[英]Can the tab selection indicator of TabLayout be pinned to the top of the screen while scrolling?
[英]TabLayout Indicator slides really slow on Tab selection
我正在使用帶有兩個嵌套 Fragment 的TabLayout
,我注意到當用戶單擊另一個 Tab 時,雖然內容立即更改,但指示器從第一個 Tab 移動到第二個需要 3-4 秒。
我在迄今為止嘗試過該應用程序的任何設備中都有相同的行為(不僅是 genymotion)。 Nexus 4 和 Nexus 5X 是一些測試設備。
布局是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:EMVideoView="http://schemas.android.com/apk/res-auto"
android:background="@color/white"
android:clickable="true"
android:layout_width="match_parent" android:layout_height="match_parent">
<com.devbrackets.android.exomedia.EMVideoView
android:id="@+id/video_play_activity_video_view"
android:layout_width="match_parent" android:layout_height="360dp"
EMVideoView:defaultControlsEnabled="true"/>
<android.support.design.widget.TabLayout
android:id="@+id/nested_tabs" android:layout_below="@+id/video_play_activity_video_view"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
app:tabMode="fixed" app:tabGravity="fill"/>
<FrameLayout android:id="@+id/fl_nested_tabs_container" android:layout_below="@+id/nested_tabs"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
以及我更改選項卡的代碼:
@Override
public void onTabSelected(TabLayout.Tab tab) {
if (isCommentsFragmentSelected) {
isCommentsFragmentSelected = false;
getChildFragmentManager()
.beginTransaction()
.replace(R.id.fl_nested_tabs_container, PollsFragment.newInstance())
.commit();
} else {
isCommentsFragmentSelected = true;
getChildFragmentManager()
.beginTransaction()
.replace(R.id.fl_nested_tabs_container, CommentsFragment.newInstance())
.commit();
}
}
在清單文件中的應用程序標簽下使用此屬性。
android:hardwareAccelerated="true"
我還使用ViewPager在三個標簽布局中使用嵌套片段。 設置屏幕外頁面限制解決了我的慢速加載問題。
viewPager.setOffscreenPageLimit(2);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.