Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – ConstraintLayout与DimensionRatio结合使用时不考虑最大宽度/高度大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
以下观点必须是正方形.我也希望将视图限制在一定的大小.不知何故,当ConsTraintLayout与同一元素上的dimensionRatio结合使用时,它忽略了max width / height属性.
<android.support.consTraint.ConsTraintLayout 
xmlns:android="http://scheR_118_11845@as.android.com/apk/res/android"
xmlns:app="http://scheR_118_11845@as.android.com/apk/res-auto"
xmlns:tools="http://scheR_118_11845@as.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://scheR_118_11845@as.android.com/apk/res/android"
xmlns:app="http://scheR_118_11845@as.android.com/apk/res-auto"
xmlns:tools="http://scheR_118_11845@as.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 – ConstraintLayout与DimensionRatio结合使用时不考虑最大宽度/高度全部内容,希望文章能够帮你解决android – ConstraintLayout与DimensionRatio结合使用时不考虑最大宽度/高度所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。