草庐IT

android - ConstraintLayout 不考虑最大宽度/高度与 DimensionRatio 的结合

coder 2023-11-25 原文

下面的 View 需要是方形的。我还想将 View 限制在一定大小。当 ConstraintLayout 与同一元素上的 dimensionRatio 结合使用时,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">
    <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 获取您的最大宽度和高度。参见 "Ratios"在文档中。

关于android - ConstraintLayout 不考虑最大宽度/高度与 DimensionRatio 的结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46339981/

有关android - ConstraintLayout 不考虑最大宽度/高度与 DimensionRatio 的结合的更多相关文章

  1. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  2. ruby-on-rails - 需要帮助最大化多个相似对象中的 3 个因素并适当排序 - 2

    我需要用任何语言编写一个算法,根据3个因素对数组进行排序。我以度假村为例(如Hipmunk)。假设我想去度假。我想要最便宜的地方、最好的评论和最多的景点。但是,显然我找不到在所有3个中都排名第一的方法。Example(assumingthereare20importantattractions):ResortA:$150/night...98/100infavorablereviews...18of20attractionsResortB:$99/night...85/100infavorablereviews...12of20attractionsResortC:$120/night

  3. ruby - 将 Ruby 中的字符串切成固定长度的字符串,忽略(不考虑/不管)新行或空格字符 - 2

    我有一个包含许多换行符和空格的字符串。我需要将它拆分成固定长度的子字符串。例如a="Thisissome\nText\nThisissometext"现在我想把它分成长度为17的字符串。所以现在它应该导致["Thisissome\nText","\nThisissometex","t"]评论:我的字符串可能包含任何字符(空格/单词等) 最佳答案 "Thisissome\nText\nThisissometext".scan(/.{1,17}/m)#=>["Thisissome\nText","\nThisissometex","t"

  4. ruby - 获取数组中值的最大连续出现次数 - 2

    下面有没有更优雅的方法来实现这个:输入:array=[1,1,1,0,0,1,1,1,1,0]输出:4我的算法:streak=0max_streak=0arr.eachdo|n|ifn==1streak+=1elsemax_streak=streakifstreak>max_streakstreak=0endendputsmax_streak 最佳答案 类似于w0lf'sanswer,但通过从chunk返回nil来跳过元素:array.chunk{|x|x==1||nil}.map{|_,x|x.size}.max

  5. ruby - 如何将 N 天添加到时间 T(考虑夏令时)? - 2

    我有一个时间对象T。向T添加N天的合理方法是什么?我想出的最好的感觉有点折磨:require'date'defadd_days(time,days)time.to_date.next_day(days).to_timeendP.S.:如果您在美国,正确答案必须满足:add_days(Time.new(2013,3,10,0),1)==Time.new(2013,3,11,0)如果您在欧盟,则正确答案必须满足:add_days(Time.new(2013,3,31,0),1)==Time.new(2013,4,1,0)P.P.S:这是一个Ruby问题,而不是Rails问题。

  6. ruby-on-rails - Rcov:为什么这段代码没有被考虑覆盖? - 2

    这是我的Controller:classMyController@list}format.json{render:json=>@list}endendendend...它所基于的助手:moduleMyHelperdefget_list_from_params(param=:id,&on_success)raw_id=params[param]beginid=Integer(raw_id)rescuerender:template=>"invalid_id",:locals=>{:id=>raw_id}elseyieldMyList.new(id)endendend...和我的功能测试(

  7. Ruby:检查东亚宽度 (Unicode) - 2

    使用Ruby,我必须将字符串以柱状格式输出到终端。像这样:|row1|astringhere|etc|row2|anotherstring|etc我可以使用String#ljust和%s处理拉丁UTF8字符。但是当字符是韩文、中文等时就会出现问题。当英文行与包含韩文等的行交错时,列根本不会对齐。如何在此处实现列对齐?有没有办法以等同于固定宽度字体的方式输出亚洲字符?对于要在Vim中显示和编辑的文档怎么样? 最佳答案 您的问题发生在CJK(中文/日文/韩文)full-widthandwidecharacters(也向下滚动图表);这些

  8. ruby - capybara 增加最大允许页面加载时间 - 2

    我有一个页面,有时加载时间超过一分钟。假设这是预期的行为并且不会改变。在这些情况下,我得到Net::ReadTimeout。请注意,这是在通过单击上一页上的按钮导航到页面之后,而不是ajax请求。因此Capybara.using_wait_time没有帮助。我尝试了一些激进的方法(其中一些我知道行不通),例如:设置page.driver.browser.manage.timeouts的implicit_wait、script_timeout和page_load。遍历整个对象空间并设置所有Selenium::WebDriver::Remote::Http::Default的timeout

  9. ruby-on-rails - Ruport vs.Prawn考虑长期使用 - 2

    我想将报告功能添加到我的rails应用程序中,而我现在正为使用哪种报告软件来创建pdf文档而苦苦挣扎。到目前为止,我确信Ruport或Prawn是最好的选择。在对它们进行了实验之后,我发现它们都非常强大,而且相当普遍,但它们也有明显的特点,我担心从长远来看,我可能会做出错误的选择。在一个大型复杂的应用程序中,ruport和prawn是如何进行长期比较的?可维护性?生成报告的代码会呈指数增长吗?代码会变得脆弱吗?可利用性?图书馆几年后还会积极维护吗?(ruportutil似乎有些过时…)可定制性?使用相同的代码库为不同的客户机生成不同的布局有多容易?最重要的是:在做出选择之前,我不知道还

  10. Ruby - 找到哈希最大值的键 - 2

    我有一个散列,我想返回散列最大值的键(或键/值对)。所以,如果只有一个真正的最大值,它将返回那个键;但是,如果有多个具有相同值的键/值对,它将返回所有这些键。我如何在Ruby中完成此操作?my_hash.max_by{|k,v|v}#onlyreturnsonekey/valuepair 最佳答案 如果你想要所有对,我会做类似的事情max=my_hash.values.maxHash[my_hash.select{|k,v|v==max}] 关于Ruby-找到哈希最大值的键,我们在Sta

随机推荐