【问题标题】:Fit entire screen (bottom and status bar) ViewPager适合整个屏幕(底部和状态栏) ViewPager
【发布时间】: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


    【解决方案1】:

    试试这个代码

         <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout 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/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >
        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
        </android.support.v4.view.ViewPager>
            <LinearLayout
                android:id="@+id/SliderDots"
                android:orientation="horizontal"
                android:gravity="center"
                android:layout_marginBottom="20dp"
                android:layout_gravity="center_horizontal|bottom|center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
            </LinearLayout>
    
    
    </FrameLayout>
    

    【讨论】:

    • 设置视图寻呼机以填充父级不起作用 - 除非这里有一些我看不到的其他更改。
    【解决方案2】:

    在 setContentView(R.layout.activity_main); 之前的 Activity 中添加这些代码行

    requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 2022-10-22
      • 1970-01-01
      • 2020-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多