Android 如何在约束布局1.0中居中视图

Android 如何在约束布局1.0中居中视图,android,center,android-constraintlayout,layout-gravity,Android,Center,Android Constraintlayout,Layout Gravity,我在constraintLayout中有一个视图(FrameLayout) 对于平板电脑设备(仅限),我希望具有此配置 1) its max height to say 100dp 2) It has to be wrap content 3) It has to be centered in its parent (vertically and horizontally). 我有义务使用constraint layout 1.0版 我尝试使用“上-下”到其父约束,但它与其父约束的“上

我在constraintLayout中有一个视图(FrameLayout)

对于平板电脑设备(仅限),我希望具有此配置

1) its max height to say 100dp 

2) It has to be wrap content 

3) It has to be centered in its parent (vertically and
horizontally).
我有义务使用constraint layout 1.0版

我尝试使用“上-下”到其父约束,但它与其父约束的“上”对齐

我试图更改app:layout\u constraintHeight\u default=“wrap”,但使其成为app:layout\u constraintHeight\u default=“spread”`违反了包装内容要求

这是我的非平板电脑布局,我了解我想制作平板电脑的所有内容,我会把它们放在
values-sw600dp
resources文件夹下

<?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="match_parent"
    android:layout_height="match_parent"
    android:background="@color/popup_view_scrim_color"
    android:fitsSystemWindows="true"
    tools:ignore="Overdraw">

  <FrameLayout
      android:id="@+id/viewToCenter"
      android:layout_width="300dp"
      android:layout_height="0dp"
      android:layout_marginTop="@dimen/account_menu_popover_top_margin"
      android:layout_marginBottom="@dimen/account_menu_popover_bottom_margin"
      android:layout_marginLeft="@dimen/account_menu_popover_side_margin"
      android:layout_marginRight="@dimen/account_menu_popover_side_margin"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHeight_default="wrap"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0">
  </FrameLayout>
</android.support.constraint.ConstraintLayout>


由于您希望视图居中,因此不需要所有这些边距:

<FrameLayout
    android:id="@+id/viewToCenter"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintHeight_default="wrap"
    app:layout_constraintWidth_default="wrap"
    app:layout_constraintHeight_max="100dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
并改为:

android:layout_width="0dp"

为什么你的
身高==0dp
0dp
CONSTRAINTLAOUT
中表示“匹配约束”。您是否尝试过使用android:layout\u width=“wrap\u content”
android:layout_width="0dp"