首页 > 解决方案 > 点击 2 次 Android Studio 后 Tablayout 不出现

问题描述

我正在使用安卓工作室。代码是java。我在片段内使用 tablayout。Tablayout 正在工作。但是当我点击那个片段 2 次时,tablayout 数据没有出现。当我单击另一个片段然后再次单击它时,它不会显示。在这些情况下,它不会显示选项卡布局的布局。可能是什么问题呢?

我的片段类:

TabLayout tabLayout ;
ViewPager viewPageronlıne;

 ViewPagerAdapter adapter = new ViewPagerAdapter(getFragmentManager());
 adapter.AddFragment(new TabOnlineSimple1(),"Simple 1");
 adapter.AddFragment(new TabOnlineSimple2(),"Simple 2");
 viewPageronlıne.setAdapter(adapter);
 tabLayout.setupWithViewPager(viewPageronlıne);

我的片段 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_height="match_parent">



        <android.support.v7.widget.Toolbar
            android:id="@+id/chatbar_layout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">



                <TextView
                    android:textStyle="bold"
                    android:id="@+id/profileanonID"
                    android:text="Online"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_centerInParent="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="10dp"
                    android:textSize="20dp" />


                <ImageView
                    android:layout_marginRight="3dp"
                    android:layout_centerInParent="true"
                    android:layout_toLeftOf="@+id/totalusershow"
                    android:src="@drawable/totaluser"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />


                <TextView
                    android:id="@+id/totalusershow"
                    android:layout_marginRight="15dp"
                    android:layout_centerInParent="true"
                    android:layout_alignParentEnd="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true" />


            </RelativeLayout>



        </android.support.v7.widget.Toolbar>




    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_below="@+id/chatbar_layout"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        android:id="@+id/tablayout_idonline"
        app:tabInlineLabel="true"
        app:tabTextAppearance="@style/TabLayoutTextStyle"
        app:tabSelectedTextColor="#00B0FF"
        app:tabTextColor="#808080"
        app:tabIndicatorColor="#00B0FF"
        app:tabMode="fixed">




    </android.support.design.widget.TabLayout>



    <android.support.v4.view.ViewPager
        android:layout_below="@+id/tablayout_idonline"
        android:layout_width="match_parent"
        android:id="@+id/viewpager_idonline"
        android:layout_height="match_parent">

    </android.support.v4.view.ViewPager>




</RelativeLayout>

标签: androidandroid-layoutandroid-fragmentsandroid-tablayout

解决方案


推荐阅读