如何修复tabLayout的一半?

时间:2017-11-04 09:29:55

标签: android android-fragments android-tablayout

在我的应用程序中,我想使用TabLayoutViewPager来显示两个fragments
我可以将Fragments显示为ViewPagerTabLayout 但是,当我从服务器获取响应时 ,然后显示此TabLayoutViewPager
但是,当显示此TabLayoutViewPager时,显示TabLayout的一半。

我的问题形象是:
enter link description here

我的XML代码:

            <LinearLayout
                android:id="@+id/celebrity_tabLayoutLay"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/profilePage_userWatchlistTitle"
                android:layout_marginTop="@dimen/padding5"
                android:orientation="horizontal"
                android:weightSum="1">
                <!--Tab Layout-->
                <com.app.test.Utils.Componenets.PlusTabLayout.TabLayoutPlus
                    android:id="@+id/celebrity_tabLayout"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:background="@color/whiteMe"
                    android:paddingBottom="@dimen/size3"
                    android:paddingLeft="@dimen/size3"
                    android:paddingRight="@dimen/size3"
                    app:tabIndicatorColor="@color/colorAccent"
                    app:tabSelectedTextColor="@color/colorAccent"
                    app:tabTextAppearance="@style/allCapsTabLayout"
                    app:tabTextColor="@color/black" />
                <!--Space-->
                <RelativeLayout
                    android:id="@+id/celebrity_emptyLay"
                    android:layout_width="0dp"
                    android:layout_height="@dimen/size50"
                    android:layout_weight="0.3" />
                <!--Filter lay-->
                <RelativeLayout
                    android:id="@+id/celebrity_filterLay"
                    android:layout_width="0dp"
                    android:layout_height="@dimen/size50"
                    android:layout_weight="0.2">
                    <!--Filter title-->
                    <TextView
                        android:id="@+id/celebrity_filterTitle"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/size24"
                        android:fontFamily="sans-serif"
                        android:gravity="center"
                        android:text="@string/sortBy"
                        android:textColor="@color/colorPrimary"
                        android:textSize="@dimen/font12" />
                    <!--Filter title line-->
                    <RelativeLayout
                        android:id="@+id/celebrity_filterTitleLine"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/size0.5"
                        android:layout_below="@+id/celebrity_filterTitle"
                        android:layout_marginLeft="@dimen/padding5"
                        android:layout_marginRight="@dimen/padding5"
                        android:background="@color/colorPrimary" />
                    <!--Filter arrow image-->
                    <ImageView
                        android:id="@+id/celebrity_filterArrowImage"
                        android:layout_width="@dimen/size18"
                        android:layout_height="@dimen/size25"
                        android:layout_alignParentRight="true"
                        android:layout_below="@+id/celebrity_filterTitle"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="@dimen/padding5"
                        android:gravity="center_vertical"
                        android:padding="@dimen/padding5"
                        android:rotation="90"
                        android:src="@drawable/ic_play"
                        android:tint="@color/newsHeaderBg" />
                    <!--Filter title-->
                    <TextView
                        android:id="@+id/celebrity_filterTxt"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/size25"
                        android:layout_below="@+id/celebrity_filterTitleLine"
                        android:fontFamily="sans-serif"
                        android:gravity="center"
                        android:text="@string/year"
                        android:textColor="@color/newsHeaderBg"
                        android:textSize="@dimen/font12" />
                </RelativeLayout>

            </LinearLayout>
            <!--ViewPager-->
            <com.app.test.Utils.Componenets.DisableSwipeViewPager
                android:id="@+id/celebrity_viewPager"
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:layout_below="@+id/celebrity_tabLayoutLay"
                android:layout_marginTop="@dimen/padding10" />

我的Java代码:

call.enqueue(new Callback<UserWatchlistResponse>() {
    @Override
    public void onResponse(Call<UserWatchlistResponse> call, Response<UserWatchlistResponse> response) {
        if (response.body().getData() != null) {
            //Set Movie tab
            celebrity_tabLayout.addTab(celebrity_tabLayout.newTabPlus());
            badgedTabCustomView = celebrity_tabLayout.getTabCustomViewAt(0);
            if (badgedTabCustomView != null) {
                badgedTabCustomView.setTabText("Movies");
                badgedTabCustomView.setTabCount(response.body().getData().getTotalMovies());
            }

            //Set Serial tab
            celebrity_tabLayout.addTab(celebrity_tabLayout.newTabPlus());
            badgedTabCustomView = celebrity_tabLayout.getTabCustomViewAt(1);
            if (badgedTabCustomView != null) {
                badgedTabCustomView.setTabText("Series");
                badgedTabCustomView.setTabCount(response.body().getData().getTotalSeries());
            }

            //Adding adapter to pager
            setupViewPager(celebrity_viewPager);
            //Set Limited viewPager
            celebrity_viewPager.setOffscreenPageLimit(2);
            //Disable Swipe viewPager
            celebrity_viewPager.disableScroll(true);
            //Adding onTabSelectedListener to swipe views
            celebrity_tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                @Override
                public void onTabSelected(TabLayout.Tab tab) {
                    celebrity_viewPager.setCurrentItem(tab.getPosition());
                }

                @Override
                public void onTabUnselected(TabLayout.Tab tab) {

                }

                @Override
                public void onTabReselected(TabLayout.Tab tab) {

                }
            });
        }
    }

    @Override
    public void onFailure(Call<UserWatchlistResponse> call, Throwable t) {

    }
});

我该如何解决?请帮帮我

0 个答案:

没有答案