【发布时间】:2021-09-24 18:47:07
【问题描述】:
我在 ConstraintLayout 中放置了一个 ViewPager,但它根本没有显示出来。任何其他视图都不会显示任何问题。这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/close_login_screen"
android:layout_gravity="left"
android:src="@drawable/icondelete"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_launcher_background"
android:layout_marginTop="60dp"
android:layout_marginBottom="40dp"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/login_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/colorPrimaryDark"
app:tabTextColor="@android:color/darker_gray"
app:tabSelectedTextColor="@color/colorPrimaryDark"
app:tabIndicatorFullWidth="false"
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"/>
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
例如,如果我使用 LinearLayout,ViewPager 会显示出来,但它根本不会滚动显示额外的内容。不确定这是否有帮助,但我想要实现的最终布局如下所示:
但是我有这个:
【问题讨论】:
-
您是否向
ViewPager提供了(电话号码和电子邮件)页面片段? -
是的,两者的片段都在那里,并且内容在线性布局中显示良好,但缺点是内容不会滚动。
-
我更新了我的答案并重建了一切。现在 Viewpager 正在正常工作。随意复制类和 XML 来尝试一下。干杯!
标签: android android-layout android-fragments