横向模式下布局不调整

Layout not adjusting in Landscape mode

我正在开发一个布局结构如下的应用程序 -

Activity A - 此 activity 是一个选项卡布局 Activity,它使用 viewpager 作为选项卡,代码如下。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_marginTop="24dp"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"  />
</android.support.design.widget.CoordinatorLayout> 

添加到 viewpager 的片段具有所有选项卡的通用布局,代码如下。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    android:background="@color/background_app"
    tools:context="com.peacecorps.pcsa.safety_tools.SafetyPlanActivity">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="@color/primary_text_default_material_dark"
        android:textSize="20sp"
        android:textStyle="bold"
        android:text="@string/safety_plan_subtitle"/>

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/safety_plan_pager"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="320dp" />

    <Button
        android:id="@+id/actionButton"
        style="@style/NavigateButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:text="@string/see_action"
        android:layout_marginTop="10dp" />
</LinearLayout>

如您所见,此片段再次包含一个 viewpager.This viewpager 将始终由下面的片段填充。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <include android:id="@+id/text_to_show"
        layout="@layout/textview"/>
</ScrollView>

其中 textview 是

<?xml version="1.0" encoding="utf-8"?>
<!--This is the common layout used for TextViews-->
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/primary_text_default_material_dark"
        android:textSize="@dimen/abc_text_size_medium_material"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/bg_textview_rounded_rectangle"
        android:padding="@dimen/textview_padding"
        android:scrollbars="vertical"
        android:fadeScrollbars="false"
        android:layout_marginBottom="@dimen/activity_vertical_margin"
        android:autoLink="web|email"
        android:textColorLink="@color/text_color_link"
    />

此处 textview 包含不同数量的文本,这些文本在 java 中为不同的选项卡动态设置。 我面临的问题是,只有 UI 的一部分在横向模式下可用,有些部分丢失,无法滚动 too.Please 帮助我,我在这个问题上坚持了很长时间。

您遇到的问题是因为您有 2 滚动行为。当 phone 处于 纵向模式时 它有很多 space 320dp 高度 ViewPager将无法占用所有可用的space,但是当phone打开时landscape mode 320dp height ViewPager会占据整个屏幕所以布局只会滚动第二个查看寻呼机,这意味着 横向模式 下的整个屏幕只能在第二个 ViewPager 上访问

请记住,底部的那些是第一个被访问的。这意味着底部的 view 具有更高的 z-index - 代码参考不是实际视图。