昨天我更新了設計支持庫從版本22.2.0到22.2.1,並且我面臨着一個奇怪的行爲TabLayout
。 在版本22.2.0上,TabLayout工作得很好,但現在它不會顯示在我的碎片中,除非我旋轉我的手機(然後出現)。 我沒有改變我的代碼,它只是停止工作。更新設計支持庫後TabLayout丟失
下面是摘錄:
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嗎? –
當然,只是編輯。謝謝。 – Leonardo
你見過:https://github.com/chrisbanes/cheesesquare?我正在使用類似的設置。 –