我在XML设计中遇到了一些问题。我已经在我的应用程序中添加了一个ViewPager,以及在应用程序顶部的一个工具栏。所以,我的问题是当我尝试将属于ViewPager的片段中的项目重力居中时,它们会被设置在ViewPager的中间,忽略了工具栏的高度。
因此,我想问一下,在父视图没有填满整个屏幕的情况下,是否可以使视图或片段中的项目居中显示。
我的活动XML如下:
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"
android:id="@+id/toolbar"></include>
<com.example.android.ui.SlidingTabLayout
android:id="@+id/module_selector_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@color/view_pager_top"
android:layout_below="@id/toolbar"
android:elevation="4dp"/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/viewPager"
android:layout_below="@id/module_selector_tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
我想居中的项目在FragmentAdapter中动态添加到Viewpager的Fragment内。
目前我的应用程序看起来像这样,我只想在整个屏幕中居中显示计时器文本和CircleProgressBar,目前它们都在viewpager的中间: