gpt4 book ai didi

android - ViewPager 中的中心 fragment

转载 作者:行者123 更新时间:2023-11-30 00:04:25 25 4
gpt4 key购买 nike

我试图实现这样一种布局:

enter image description here

问题是我无法在 viewpager 上将 fragment 居中。我已经尝试改变重力,但我做不到。有一些我的代码:

 <android.support.design.widget.CollapsingToolbarLayout
>


<RelativeLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:gravity="center" />



</RelativeLayout>
(...)
</android.support.design.widget.CollapsingToolbarLayout>

fragment child 有那个代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/infos"
android:weightSum="3"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
(...)</LinearLayout>

通过这段代码,我得到了这样的结果:

enter image description here

最佳答案

请像这样更新您的布局:

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_marginTop="25dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
/>
Feel free to tailor padding/height to fit your UI.

关于android - ViewPager 中的中心 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49268412/

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