将片段附加到framelayout

时间:2018-03-03 12:00:12

标签: android android-fragments

我在我的活动中有一个FrameLayout,我根据在NavigationDrawer中选择的项目附加片段。问题是片段没有完全填充Framelayout,虽然宽度和高度设置为MATCH_PARENT,我也已经尝试删除填充和边距,但白色空间仍然存在。以下是显示问题的屏幕截图以及xml文件。如何删除空白区域并使地图填满整个framelayout?

Fragment width and height

Framelayout width and height

活动布局:

<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">



<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/tb_actionbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>


    <FrameLayout
        android:layout_margin="0dp"
        android:padding="0dp"
        android:id="@+id/container"
        android:name="com.example.styledmap.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawermenu"/>

片段布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="@+id/cl_fragment"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent">


<com.google.android.gms.maps.MapView
    android:id="@+id/google_map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/tv_delete_marker"
    android:layout_width="match_parent"
    android:layout_height="43dp"
    android:layout_alignBottom="@id/google_map"
    android:layout_marginStart="8dp"
    android:text="@string/tv_delete"
    android:textAlignment="center"
    android:textSize="16sp"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />


<Button
    android:id="@+id/btn_add_place"
    android:layout_width="64dp"
    android:layout_height="64dp"
    android:layout_margin="16dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="48dp"
    android:background="@drawable/ic_add_circle_black_24dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.871"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/google_map"
    app:layout_constraintVertical_bias="0.92" />

1 个答案:

答案 0 :(得分:1)

<MapView>

中删除边距
<com.google.android.gms.maps.MapView
    android:id="@+id/google_map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />