将视图设置为与android布局中的父视图匹配

将视图设置为与android布局中的父视图匹配,android,xml,android-layout,view,infowindow,Android,Xml,Android Layout,View,Infowindow,我的信息窗口布局有一个小问题。 我试图在布局中设置一个视图,以在宽度上与父视图匹配,但我在左右边距中得到一些小间隙。 我尝试使用LinearLayout、RelativeLayout和ConstraintLayout作为根视图,得到了相同的结果 以下是我的XML: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://sc

我的信息窗口布局有一个小问题。 我试图在布局中设置一个视图,以在宽度上与父视图匹配,但我在左右边距中得到一些小间隙。 我尝试使用LinearLayout、RelativeLayout和ConstraintLayout作为根视图,得到了相同的结果

以下是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_margin="0dp"
                                         android:orientation="vertical"
                                         android:padding="0dp">

<View
    android:id="@+id/view"
    android:layout_width="0dp"
    android:layout_height="30dp"
    android:layout_marginTop="0dp"
    android:background="@color/login_button_color"
    android:orientation="horizontal"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</View>

<de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/profile_image_info_view"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="80dp"
    android:layout_marginRight="80dp"
    android:layout_marginTop="45dp"
    android:layout_weight="2"
    android:src="@drawable/com_facebook_profile_picture_blank_portrait"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0"
    tools:ignore="InefficientWeight"
    android:layout_marginStart="80dp"
    android:layout_marginEnd="80dp"/>

<TextView
    android:id="@+id/owner_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_margin="10dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    android:layout_weight="1"
    android:gravity="center_horizontal"
    android:text="@string/placeholder"
    android:textColor="@android:color/black"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.503"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/profile_image_info_view"
    app:layout_constraintVertical_bias="0.17000002"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"/>

<TextView
    android:id="@+id/event_title_info_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="40dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_weight="1"
    android:foregroundGravity="center_horizontal"
    android:gravity="center_horizontal"
    android:text="@string/placeholder"
    android:textColor="@color/com_facebook_button_background_color"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.503"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/owner_name"
    app:layout_constraintVertical_bias="0.92"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"/>

</android.support.constraint.ConstraintLayout>
提前谢谢你


<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/view"    
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:background="@color/colorAccent"
        android:orientation="horizontal"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"       
        app:layout_constraintTop_toTopOf="parent">

    </View>
</android.support.constraint.ConstraintLayout>
编辑:

在dimens.xml中更改此选项

<dimen name="activity_horizontal_margin">0dp</dimen>

<dimen name="activity_vertical_margin">0dp</dimen>
0dp
0dp

编辑:

在dimens.xml中更改此选项

<dimen name="activity_horizontal_margin">0dp</dimen>

<dimen name="activity_vertical_margin">0dp</dimen>
0dp
0dp

使约束窗口的宽度与父级匹配。可能您的ConstraintLayout从其子项获取宽度大小。

使您的ConstraintLayout的宽度与父项匹配。可能您的约束从其子对象获取宽度大小。

您在
getInfoContents()
方法中编写的代码将其移动到
getInfoWindow()
方法

如果您使用
getInfoContents()
方法,那么它将添加带有一些填充的白色背景,但
getInfoWindow()
方法不会这样做

更新代码为:

mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
    @Override
    public View getInfoWindow(Marker marker) {
        View view = getLayoutInflater().inflate(R.layout.fragment_info_view, null);
        profileImageInfoView = (CircleImageView) 
        view.findViewById(R.id.profile_image_info_view);
        ownerName = (TextView)view.findViewById(R.id.owner_name);
        eventTitle = (TextView)view.findViewById(R.id.event_title_info_view);
        return view;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }
});

您在
getInfoContents()
方法中编写的代码将其移动到
getInfoWindow()
方法

如果您使用
getInfoContents()
方法,那么它将添加带有一些填充的白色背景,但
getInfoWindow()
方法不会这样做

更新代码为:

mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
    @Override
    public View getInfoWindow(Marker marker) {
        View view = getLayoutInflater().inflate(R.layout.fragment_info_view, null);
        profileImageInfoView = (CircleImageView) 
        view.findViewById(R.id.profile_image_info_view);
        ownerName = (TextView)view.findViewById(R.id.owner_name);
        eventTitle = (TextView)view.findViewById(R.id.event_title_info_view);
        return view;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }
});


请发布信息窗口的代码。我只是用LayoutFlater设置了它,并用onMarkerClick打开了它,我还没有对它做任何操作。为什么视图中的宽度为0?它是一个约束布局,作为根视图,当我为您使用此布局的内容设置约束时,它就是这样设置的?对话工具栏?其他?请发布信息窗口的代码。我只是用layoutInflater设置它,然后用onMarkerClick打开它,我还没有用它做任何事情。为什么视图中的宽度为0?它是一个约束布局,作为根视图,当我设置约束时,它就是这样设置的。你使用这个布局的目的是什么?对话工具栏?其他?没有改变任何内容Sadly我相信它作为一个片段工作,但我在MapFragment中使用它作为一个信息窗口,我得到了相同的结果我用膨胀的方式更新了问题,MapFragment以编程方式打开并从默认的MapFragment膨胀,我没有在dimens.xml
0dp
0dp
中更改以下内容的布局。我相信它可以作为一个片段工作,但我在MapFragment中将它用作一个信息窗口,我得到了相同的结果我用膨胀的方式更新了问题,MapFragment是以编程方式打开并从默认MapFragment中膨胀的,我没有在dimens.xml
0dp
0dp
中更改以下内容的布局,同样的结果,如果我更改视图宽度以匹配父视图,则信息窗口只会延伸到地图宽度,但是我仍然有一个带有linearlayout的gapschange视图子项,并使宽度匹配父项。同样的结果,如果我更改视图宽度以匹配父项,则信息窗口只会延伸到地图宽度,但我仍然有一个带有linearlayout的gapschange视图子项,并使宽度匹配父项。