【发布时间】:2019-07-11 13:56:47
【问题描述】:
我无法用我的背景填充整个屏幕。我有绿色背景的 main_activity 来检查它是否填满了整个屏幕并且可以正常工作。主要活动按我的意愿正确填满整个屏幕。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:background="@color/colorPrimaryDark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.viewpager.widget.ViewPager
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
/>
<!--android:layout_marginTop="-20dp"
android:layout_marginBottom="-20dp"/-->
<com.tbuonomo.viewpagerdotsindicator.WormDotsIndicator
android:id="@+id/pager_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:dotsColor="@color/colorPrimaryDark"
app:dotsStrokeColor="@color/colorPrimaryDark"
app:dotsCornerRadius="8dp"
app:dotsSize="16dp"
app:dotsSpacing="4dp"
app:progressMode="true"
android:layout_marginTop="25dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
现在我有了橙色背景的片段。我已设置宽度和高度以匹配父项和 fitSystemWindows,与主要活动中相同,但它不适合 100% - 状态栏和底部栏不受影响。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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/constraintLayout"
android:background="@drawable/pantry_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<TextView
android:id="@+id/label"
android:text="@string/fragment_pantry"
app:layout_goneMarginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="75dp"
android:layout_marginBottom="@dimen/activity_vertical_margin"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"/>
</androidx.constraintlayout.widget.ConstraintLayout>
效果在下面的屏幕上可见。我尝试了一个负边距的简单解决方法,但我担心它会如何在其他设备上运行。
PS:手机有缺口...怀疑与它有什么关系。
【问题讨论】:
标签: android user-interface android-fragments android-viewpager