ViewPager与协调布局 [英] ViewPager with Coordinator Layout

查看:203
本文介绍了ViewPager与协调布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动的布局,如下所示:

I have an activity layout that looks like the following:

<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具有两个片段,一个具有RecyclerView和一个具有LinearLayout中。

The viewpager has two fragments, one with a RecyclerView and one with a LinearLayout.

与RecyclerView的片段为预期和操作栏滚动关闭时RecyclerView滚动屏的工作原理。

The fragment with RecyclerView works as expected and the action bar scrolls off screen when the RecyclerView is scrolled.

与LinearLayout中的另一个片段不显示,我想它不过。该LinearLayout中的绘制TabLayout下方,并延伸屏幕外。我想它没有屏幕外延伸被调整,以填补TabLayout下方的可用空间。在LinearLayout中是这样的:

The other fragment with the LinearLayout isn't displaying as I would like it to however. The LinearLayout is drawn below the TabLayout and extends offscreen. I would like it to be resize to fill the space available below the TabLayout without extending offscreen. The LinearLayout looks like this:

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

感谢您的帮助,很多AP preciated!

Thanks for any help, much appreciated!

推荐答案

我想你需要嵌套的滚动视图添加到您的LinearLayout。

I think you need to add nested scroll view to your linearlayout.

这篇关于ViewPager与协调布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆