【发布时间】:2015-10-10 23:03:14
【问题描述】:
我昨天将设计支持库从版本 22.2.0 更新到了 22.2.1,我遇到了 TabLayout 的奇怪行为。
在版本 22.2.0 上,TabLayout 工作得很好,但现在它不会显示在我的片段中,除非我旋转我的手机(然后它会出现)。
我没有更改我的代码,它只是停止工作。
这里是sn-ps:
public class FriendFragment extends Fragment {
@Bind(R.id.friendPager)
ViewPager viewPager;
@Bind(R.id.friendSlideTab)
TabLayout tabLayout;
...
@Override
public void onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_friend,container,false);
ButterKnife.bind(this,v);
return v;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
list.add(new SlideFragment(getString(R.string.my_friends), new MyFriendsFragment()));
list.add(new SlideFragment(getString(R.string.add_friend), new SearchFriendFragment()));
adapter = new FragmentSliderAdapter(list, getChildFragmentManager());
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/friendSlideTab"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/friendPager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" />
</LinearLayout>
我使用 ButterKnife,认为它不会有任何区别,因为在以前的版本中它正在使用它。
谢谢,任何帮助将不胜感激!
【问题讨论】:
-
您不能向我们展示您的整个 XML 吗?
-
当然,刚刚编辑。谢谢。
-
你看到了吗:github.com/chrisbanes/cheesesquare?我正在使用类似的设置。
-
我看过他们的代码,看起来很像我的,但这根本不能解决我的问题。再次感谢您的回答!
-
你的 XML 看起来根本不像他的。尝试使用他的示例并减慢删除额外视图以匹配您的视图。
标签: android android-layout android-support-library butterknife android-tablayout