适合整个屏幕(底部和状态栏)ViewPager

时间:2019-02-18 08:16:39

标签: android user-interface android-fragments android-viewpager

我无法用背景填充整个屏幕。我的main_activity具有绿色背景,以检查它是否填满整个屏幕并且可以工作。主要活动可以适当地填满整个屏幕。

public static void printCalc() {
    ArrayList<Shape> list = new ArrayList <Shape> ();
    for (int i = 0; i < list.size(); i++) {
        System.out.println(list.get(i)+"Area: "+list.get(i).calcArea()+" Circumference: "+list.get(i).calcCircumference());
    }
}
public static void printMenu1() {
    System.out.println( "1. Add new shape\r\n" + 
            "2. List all shapes\r\n" +
            "3. Sum all circumferences\r\n" +
            "4. Sum all areas\r\n" +
            "5. Find biggest circumference\r\n" +
            "6. Find biggest area\n" +
            "7. Exit" +
            "Enter a number from the list above");
}
public static void printMenu2() {
    System.out.println( "1. Square\r\n" + 
            "2. Rectangle\r\n" + 
            "3. Circle\r\n" + 
            "4. Right triangle\r\n" + 
            "Enter a number from the list above");
}
public static void main (String[] args) {       
    int i = 0; 
    int val, val1 = 0;

    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    printMenu1();
    while (true) {          
        val=sc.nextInt();
        if (val == 7) {
            System.out.println("Exit");
            break;                           
        }                     
        if (val == 1)
            printMenu2();
        val=sc.nextInt();   

        if (val == 1)
            System.out.println("Enter Square width");
        val=sc.nextInt();
        ArrayList<Shape> list = new ArrayList <Shape> ();
        list.add(new Square(val));
        printCalc();

        if (val == 2) {
            System.out.println("Enter Rectangle height");
            val=sc.nextInt();
            System.out.println("Enter Rectangle width");
            val=sc.nextInt();
            val1=sc.nextInt();
            list.add(new Rectangle(val,val1));
            printCalc();
        }
        if (val == 3) {
            System.out.println("Enter Circle radius");
            val=sc.nextInt();
            list.add(new Circle(val));
            printCalc();
        }

        if (val == 4) {
            System.out.println("Enter Right triangle height");
            val=sc.nextInt();
            System.out.println("Enter Right triangle width");
            val1=sc.nextInt();
            list.add(new Triangle(val,val1));
            printCalc();
        }
        if (val1 == 2) {
            System.out.println("2. List all shapes");
            printCalc();
            val1=sc.nextInt();
        }   
        if (val1 == 3) {
            System.out.println("3. Sum all circumferences");

            for (int i1 = 0; i1 < list.size(); i1++) {
                for (int i2 = 0; i2 < list.size(); i2++) {
                    list.get(i1).calcCircumference();
                }
            }
            System.out.println(list.get(i)+" Circumference: "+ list.get(i).calcCircumference());    
            val1=sc.nextInt();
        }   
        if (val1 == 4) {
            System.out.println("4. Sum all areas");
            val1=sc.nextInt();
        }
        if (val1 == 5) {
            System.out.println("5. Find biggest circumference");
            val1=sc.nextInt();
        }   
        if (val1 == 6) {
            System.out.println("6. Find biggest area");
            val1=sc.nextInt();
        }
    }
}

现在,我的片段带有橙色背景。我已设置宽度和高度以匹配父级和fitSystemWindows,与主活动中的相同,但它不适合100%-状态栏和底部栏不受影响。

<?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>

效果在下面的屏幕上可见。我尝试了一种具有负边距的简单变通方法,但是我担心它在其他设备上的工作方式。

PS:电话有缺口...怀疑与它有关。

screen

2 个答案:

答案 0 :(得分:0)

尝试此代码

     <?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>

答案 1 :(得分:0)

将这些代码行添加到setContentView(R.layout.activity_main);之前的活动中。

  

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