首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ConstraintLayout layout_constraintDimensionRatio不工作

ConstraintLayout layout_constraintDimensionRatio不工作
EN

Stack Overflow用户
提问于 2017-05-20 05:32:41
回答 4查看 24.2K关注 0票数 26

我使用了constraintLayoutlayout_constraintDimensionRatio="1:1" (宽度是wrap_content,身高是0dp (match_constraint))

因此,我预计宽度和高度是1:1,但它不起作用。

怎么啦?

我附上了密码和截图。

代码语言:javascript
运行
复制
<?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">

    <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:background="@android:color/holo_blue_bright"
        android:gravity="center"
        android:text="Hello World!11"
        app:layout_constraintDimensionRatio="1:1" />

</android.support.constraint.ConstraintLayout>

屏幕截图

我引用android开发者关于Constraintlayout布局的网站。https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#DimensionConstraints

比例:你也可以定义一个小部件的一个维度作为另一个小部件的比率。为此,需要至少将一个受限维度设置为0dp (即MATCH_CONSTRAINT),并将属性layout_constraintDimentionRatio设置为给定的比率。例如:

EN

Stack Overflow用户

发布于 2018-04-16 15:29:24

作为1.1.0版本,这种情况已经改变了。

现在您可以定义:

代码语言:javascript
运行
复制
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintDimensionRatio="W,1:1"
app:layout_constraintDimensionRatio="H,1:1"

请查看下面的链接,查找有关DimensionConstraints的所有文档:

链接到文档

票数 13
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44082305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档