【发布时间】:2020-05-15 16:20:56
【问题描述】:
目前,我正在开发对不同方向的支持。我的横向布局有一个 viewpager 和 tablayout,纵向布局只有一个片段。当我以任何方向启动应用程序时,布局都可以正常工作。但是,当在运行时改变方向时,在这种情况下从纵向到横向,viewpager 和 tablayout 完全从屏幕上消失,即使分配了权重,也只留下父级高度和宽度的片段。
这让我相信布局没有正确更改。我也没有将 android:configurations 应用于我的清单。否则,当我改变它们的方向时,其他活动和片段可以正常工作。出于某种原因,只有这不起作用。我将在下面附上 XML 代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer"
tools:context=".HomeActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:ignore="UselessParent">
<fragment
android:id="@+id/none"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="fragment_tag"
android:name="com.example.trackeths.HomeFragment" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabTextColor="#fff"
app:tabIndicatorColor="#fff"
android:background="@color/colorPrimaryDark"
/>
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"/>
</LinearLayout>
【问题讨论】:
标签: android android-fragments android-viewpager