android – ConstraintLayout与DimensionRatio结合使用时不考虑最大宽度/高度

以下观点必须是正方形.我也希望将视图限制在一定的大小.不知何故,当ConstraintLayout与同一元素上的dimensionRatio结合使用时,它忽略了max width / height属性.
<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">
    <View 
       android:layout_width="0dp"
       android:layout_height="0dp"
       app:layout_constraintTop_toTopOf="@+id/guideline_top"
       app:layout_constraintDimensionRatio="1:1"
       app:layout_constraintLeft_toLeftOf="@+id/guideline_left"
       app:layout_constraintRight_toRightOf="@+id/guideline_right"
       app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom" 
       app:layout_constraintWidth_max="100dp"
       app:layout_constraintHeight_max="100dp"/>

目前我通过将View放入容器中来使用解决方法,如下所示.但我宁愿保持我的布局层次尽可能平坦.

<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.support.constraint.ConstraintLayout 
          android:layout_width="0dp"
          android:layout_height="0dp"
          app:layout_constraintTop_toTopOf="@+id/guideline_top"
          app:layout_constraintLeft_toLeftOf="@+id/guideline_left"
          app:layout_constraintRight_toRightOf="@+id/guideline_right"
          app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom"
          app:layout_constraintWidth_max="100dp"
          app:layout_constraintHeight_max="100dp"> 
             <View 
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" 
                />

这是约束布局中的限制,您不能将最大宽度/高度与尺寸比结合使用吗?

我正在使用ConstraintLayout v1.0.2.

解决方法

指定任一个
`app:layout_constraintDimensionRatio="H,1:1"`

要么

`app:layout_constraintDimensionRatio="W,1:1"`

这应该导致ConstraintLayout获取您的最大宽度和高度.请参阅doc中的“Ratios”.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...