android - 点击 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>
解决方案
推荐阅读
- c++ - 为什么这个“while(cin.get(str,3))”只运行一次,无论你输入什么?
- sql - 专用排序列的命名约定
- javascript - Nodejs 如何添加另一个主 app.js 并使用它们来使我的代码干净?
- javascript - 如何给 SwiperJS 添加两种不同的效果?
- c# - 使用 Google Contact People API C# 读取隐私标志
- file - 批处理文件从文件夹中复制一次文件并等待下一个文件
- java - TableRow 正在提供反向 TextViews
- java - 多态性 + 重载 - 如何调用子类的多态/重载方法?
- sql-server - Azure Devops,在构建中测试部署
- mysql - 错误 2013 (HY000): 查询期间失去与 MySQL 的连接