调整viewpager内部的视图大小,以弥补标签的高度 [英] Adjust view size inside viewpager, make up for tab height
问题描述
ViewPager的三个选项卡中的每个选项卡都加载有片段,我遇到了一些问题.在第一个片段中,有一个带有ListView的垂直LinearLayout.列表视图会动态加载项目,但是当项目数超过屏幕大小时,它不会滚动以显示其余项目.
I'm having a bit of a problem with a ViewPager that loads fragments for each of its three tabs. Inside the first fragment, there's a vertical LinearLayout with a ListView. The list view is dynamically loaded with items, but when the item count exceeds the screen size, it doesn't scroll to show the rest of the items.
我的猜测是,该片段(设置为与父代的高度匹配)被父代布局(DrawerLayout内部的CoordinatorLayout)的tabview向下推.如何弥补ViewPager中TabView的高度或强制片段将其大小限制为剩余的屏幕高度?
My guess is that the fragment (which is setup to match the parent's height) is pushed down by the tabview in the parent layout (a CoordinatorLayout inside a DrawerLayout). How can I make up for the TabView height in the ViewPager or force the fragment to limit it's size to the remaining screen height?
以下是该应用的图片:
Here's an image of the app:
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home"
app:menu="@menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>
fragment_account.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/accounts_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.mycompany.myapp.fragments.AccountsFragment" />
推荐答案
我通过从工具栏中删除app:layout_scrollFlags属性来解决此问题.我认为该应用程序正在等待我滚动以隐藏工具栏,这将使片段缺少高度调整.
I fixed the issue by removing the app:layout_scrollFlags attribute from the toolbar. I figure the app was waiting for me to scroll to hide the toolbar, which would give the fragment the missing height adjustment.
这篇关于调整viewpager内部的视图大小,以弥补标签的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!