【问题标题】:ViewPager with Coordinator Layout带有协调器布局的 ViewPager
【发布时间】:2015-08-07 03:51:31
【问题描述】:

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

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

带有 RecyclerView 的片段按预期工作,并且当 RecyclerView 滚动时,操作栏会滚动到屏幕外。

LinearLayout 的另一个片段没有像我希望的那样显示。 LinearLayout 绘制在 TabLayout 下方并延伸到屏幕外。我希望调整它的大小以填充 TabLayout 下方的可用空间,而无需扩展屏幕外。 LinearLayout 如下所示:

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

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

【问题讨论】:

  • 你解决了吗?我也有同样的问题。谢谢!
  • 我从来没有真正找到解决这个问题的令人满意的方法。我最终做的是在我的 LinearLayout 底部添加一个边距,该边距等于 appbar 的高度。这会将所有内容保留在屏幕上,但如果应用栏因滚动其他片段之一而折叠,则边距将显示为空白。

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


【解决方案1】:

我认为您需要将嵌套滚动视图添加到您的线性布局中。

【讨论】:

    【解决方案2】:

    Alex 我知道你必须在两个片段中使用两个 CoordinatorLayout,你可以在其中包含你的线性布局。

    【讨论】:

      猜你喜欢
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 2015-10-29
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多