ViewPager在协调器布局中的高度超过了可用高度 [英] ViewPager's height in Coordinator layout is more than available

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

问题描述

我有一个CoordinatorLayout,其中AppBarLayout内有一个Toolbar和一个TabLayout.另外,我在CoordinatorLayout内部但在ViewPager外部有一个ViewPager.

I have a CoordinatorLayout with a Toolbar and a TabLayout inside the AppBarLayout. Additionally, I have a ViewPager inside the CoordinatorLayout but outside the ViewPager.

问题是ViewPager's的高度大于实际可用高度,导致我的Fragment的某些视图被剪切了.

The problem is that the ViewPager's height is bigger than what is actually available, resulting in some views from my Fragment being cut.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/lightGray"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar2"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:scrollbars="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="false"/>

    </android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>

这就是我说ViewPager高度错误时的意思.

And this what I mean when I say that the ViewPager has the wrong height.

推荐答案

可能的破解方法是添加与工具栏相同的底边距,即

A possible hack can be adding same bottom margin as toolbar which is

?attr/actionBarSize .您甚至可以摆弄其他可能的ui边距漏洞,以获取最佳结果.

?attr/actionBarSize . You can even fiddle around with other possible ui hacks of margins to give you best result.

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

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