android - 具有协调器布局的 ViewPager

标签 android android-layout android-fragments android-coordinatorlayout

我有一个如下所示的 Activity 布局:

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

<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"
        app:layout_scrollFlags="scroll|enterAlways"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

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

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

viewpager 有两个 fragment ,一个带有 RecyclerView,一个带有 LinearLayout。

带有 RecyclerView 的 fragment 按预期工作,当滚动 RecyclerView 时,操作栏会滚出屏幕。

不过,另一个带有 LinearLayout 的 fragment 没有像我希望的那样显示。 LinearLayout 绘制在 TabLayout 下方并延伸到屏幕外。我希望调整它的大小以填充 TabLayout 下面的可用空间而不扩展到屏幕外。线性布局看起来像这样:

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

    <LinearLayout
        android:id="@+id/station_detail_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            layout="@layout/station_detail_title"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3" />

        <include
            layout="@layout/station_detail_body"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2" />


    </LinearLayout>

    <TextView
        android:id="@+id/text_view_station_detail_empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/text_view_station_detail_empty"
        android:visibility="gone" />
</LinearLayout>

感谢您的帮助,非常感谢!

最佳答案

我认为您需要将嵌套 ScrollView 添加到您的线性布局中。

关于android - 具有协调器布局的 ViewPager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31869406/

相关文章:

android - java.lang.OutOfMemoryError : bitmap size exceeds VM budget in Appcelerator Titanium 错误

android - 如何像在 Android Market 应用程序中一样创建进度指示器?

android - 当一个fragment失去焦点然后又重新获得焦点时,为什么它的onResume()方法在此期间一直没有被调用?

java - 尽管设置了必要的属性,列表项也不会保持选中状态

java - 无法从runtime.getruntime.exec()运行/获取输出(android java)

android - 当 Android Activity 的回调在方向更改后变为 null 时,更新回调引用的正确方法是什么

android - 在android中使用动画更改布局宽度

java - 折叠工具栏布局: How to make a view disappear when collapsed

android - 无法在 onLoadFinished 内执行此操作

android - adb连接两部智能手机时得到两个相同的序列号