gpt4 book ai didi

android - 当父 View 未填满整个屏幕时, fragment 中的中心项目

转载 作者:行者123 更新时间:2023-11-29 01:20:08 25 4
gpt4 key购买 nike

我的 XML 设计遇到了一些问题。我在我的应用程序中添加了一个 Viewpager,并在应用程序顶部添加了一个工具栏。所以,我的问题是,当我尝试将属于我的 Viewpager 的 fragment 中的项目重心居中时,将设置在 Viewpager 的中间,忽略工具栏高度。

所以,我想问一下,当它们的父 View 没有填满整个屏幕时,是否可以将 View 或 fragment 中的项目居中放置在屏幕中间。

我的 Activity 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 的中间对齐:

enter image description here

最佳答案

这是关于 fragment ,而不是 Viewpager。你能粘贴 fragment 的布局吗?

从图像上看,我要做的是带有两个子项的垂直线性布局,第一个用于圆圈,另一个用于按钮。

然后,您可以使用 layout_weight 来控制子项的开始和结束位置。

关于 layout_weight 的更多信息: https://developer.android.com/guide/topics/ui/layout/linear.html#Weight

抱歉,我现在没有布局编辑器。

关于android - 当父 View 未填满整个屏幕时, fragment 中的中心项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37335227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com