android - 选项卡布局内容未显示在 fragment 布局内

标签 android android-layout android-fragments android-tablayout

我有一个 BottomNavigationView,它有三个选项卡。一个 BottomNavigationView 包含 TabLayout。我的问题是为什么 TabLayout 内容没有显示。仅显示选项卡标题。

这是一个 XML fragment 。

 <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"/>

关于android - 选项卡布局内容未显示在 fragment 布局内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52165374/

相关文章:

android - 旋转后所有 fragment 可见

android-layout - 在滑动选项卡中水平滚动 : android

android - 如何在自定义 ViewGroup 中正确扩展 XML-Layout-File?

android - 构建 APK 时 MPAndroidChart Android Studio 错误

java - 使用 picasso 将图像大小调整为全宽和固定高度

java - NavigationDrawerActivity 和 BottomNavigationActivity

java - 旋转期间无法保存 fragment 状态

java - Android 应用程序无法在启动时运行 1 个 Activity 和 1 个类

android - 媒体播放器的搜索者

未找到证书路径的 Android Volley 自签名 HTTPS 信任 anchor