[英]Tab layout content not showing inside a Fragment layout
我有一個BottomNavigationView
,它有三個選項卡。 一個BottomNavigationView
包含TabLayout
。 我的問題是為什么沒有顯示TabLayout
內容。 僅顯示選項卡標題。
這是一個片段 XML。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txt_profile_about_me"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textAlignment="viewStart"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_gathring_count" />
<android.support.design.widget.TabLayout
android:id="@+id/profile_tabs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_profile_about_me"
app:layout_constraintVertical_bias="1.0"
/>
<android.support.v4.view.ViewPager
android:id="@+id/profile_viewpager"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
我的代碼如下。
ViewPager viewPager = (ViewPager) view.findViewById(R.id.profile_viewpager);
ProfileTabAdapter adapter = new ProfileTabAdapter(getChildFragmentManager());
// Set the adapter onto the view pager
viewPager.setAdapter(adapter);
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) view.findViewById(R.id.profile_tabs);
tabLayout.setupWithViewPager(viewPager);
標簽內容未顯示。 任何建議。
正確約束您的 viewPager。
嘗試這個:
<android.support.v4.view.ViewPager
android:id="@+id/profile_viewpager"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_tabs"
app:layout_constraintBottom_toBottomOf="parent"/>
嘗試添加:
app:layout_constraintTop_toBottomOf="@+id/profile_tabs"
到ViewPager
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.