jjzjj

Android Layout_weight

coder 2023-12-25 原文

也许我误解了 layout_weight 参数,但我不明白为什么这样的东西不起作用......

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" android:weightSum="1">

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>

<TextView
    android:id="@+id/textView2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.2"
    android:text="TextView" 
    android:background="@color/apr_brightyellow"/>

<TextView
    android:id="@+id/textView3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:text="TextView" 
    android:background="@color/apr_yellow"/>

</LinearLayout>

我在 LinearLayout 中有三个或更多 TextView 。 我想将它们放在具有百分比宽度的列中。 这就是它产生的结果:

layout_weight 设置为 0.3/0.2/0.5

然后我稍微改变了 layout_weight 参数如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" android:weightSum="1">

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>

<TextView
    android:id="@+id/textView2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.3"
    android:text="TextView" 
    android:background="@color/apr_brightyellow"/>

<TextView
    android:id="@+id/textView3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.4"
    android:text="TextView" 
    android:background="@color/apr_yellow"/>

</LinearLayout>

现在我得到了我想要的:

layout_weight 设置为 0.3/0.2/0.5

这是一个错误还是我真的误解了 layout_weight 的全部内容?

最佳答案

当您使用 android:layout_weight 时,您应该设置 android:layout_width="0dp"(以防垂直方向 - android:layout_height="0dp")。

关于Android Layout_weight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10547499/

有关Android Layout_weight的更多相关文章

  1. android - Layout_weight 不能正常工作 - 2

    我有followinxml,我想要imageview,然后是两个textview,然后是imageview,但它不能正常工作。这是我计划拥有的:这是我得到的: 最佳答案 内部线性布局必须有0宽度 关于android-Layout_weight不能正常工作,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/35569495/

  2. android - 如何修复线性布局中的layout_weight? - 2

    在我的xml文件中,我将每个小圆圈(ImageView)设置为具有线性View和layout_weights的屏幕的25%的大小。.这是我手机的屏幕截图(它应该是什么样子)在我的平板电脑上它不会将大小更改为屏幕的25%(这是它的外观)我的代码由三个LinearLayout组成每个包含ImageView的权重为0.25(满分1)。代码如下: 最佳答案 您不能使用png文件作为您的circle_white。如果您选择正确的android:scaleType,从技术上讲您可以完成这项工作,但它会导致可怕的别名渲染。我会先删除您现有的png

  3. android- layout_weight ="0"的含义 - 2

    我正在使用layout_weight指定android中特定viewGroups中各种View的比例。来自this问题的答案我对layout_weight是什么有一个清晰的概念。我使用普通数学计算了viewGroup中所有views的大小(即我有3个views1,2&3layout_weights并且它们都有layout_height="0dp"然后它们有1/(1+2+3),2/(1+2+3),3/(1+2+3)viewGroup中的空格用于垂直对齐)。但是,layout_weight="0"是什么意思?如何确定layout_weight="0"的View大小?

  4. php - 具有 "weighted"条边的 Ford-Fulkerson 算法 - 2

    Ford-Fulkerson是否有任何变体可以为边缘增加额外的“重量”维度?我的意思是,有些边比其他边更理想,虽然所有的可能性都存在,但它会优先考虑理想的边而不是不太理想的边。 最佳答案 据我所知,有两种常见的概括方法可以增加权重。最小成本流假设您对每条边都有一个权重,并且想要计算满足约束且成本最低的流。(成本=权重之和*沿关联边流动的单位)这个问题叫做minimumcostflow.可以在networkx中找到一个名为min-cost-flow的实现.这是一个很好的topcodertutorial在原始对偶方法上。我最喜欢的算法实

  5. php - 如何使用 PHP 和正则表达式将 <span style ="font-weight: bold;">foo</span> 替换为 <strong>foo</strong>? - 2

    我有这样一个字符串:Foo我想用PHP来制作Foo…不影响其他span。我该怎么做? 最佳答案 $text='Foo';$text=preg_replace('/(.*?)/','$1',$text);注意:仅适用于您的示例。 关于php-如何使用PHP和正则表达式将foo替换为foo?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/2728789/

  6. php - 修改 Drupal 表单字段 - 数组中的 [#weight] 不被尊重? - 2

    我没有使用php的经验。我按照一些教程使用template.php中的主题方法修改了我的Drupal表单。由于某些原因,字段的[#weight]属性不符合其值。我想将类别字段[cid]移到主题字段[subject]上方。这些是我使用的代码行:$form['cid']['#weight']=0.003;$form['subject']['#weight']=0.004;当我打印我的数组以查看时,我看到值已经更改,但是当我呈现表单时没有进行任何更改。我已经在每次修改后清除了性能缓存。这是我打印的数组的片段:[subject]=>Array([#type]=>textfield[#title

  7. java - API的 ‘power-to-weight ratio’是什么? - 2

    在Bloch的演讲中,他说设计师应该为API寻找良好的功率重量比。此外,他还强调“概念重量比体积更重要”。我猜权重是针对“概念权重”的,bulk是针对类的方法数。但我无法理解什么是“概念重量”,什么是“功率重量比”。欢迎任何解释!Bloch举了一个例子:List.subList()有很好的“功率重量比”。如果客户想知道子列表的索引,他不需要调用低“p2wratio”方法indexOfSubList(a,b,e),相反,他可以调用List.subList(a,b).indexOf(e).Bloch认为这是“功率重量比”。来源:API应该越小越好API应满足其要求如有疑问,请将其删除功能、

  8. c++ - boost++::weighted_median 和 eigen::vectorXf --newbie - 2

    我想得到一个未排序的变量的加权中位数长度,Eigenc++vectorXf对象。看来我可以使用boost来自boost统计累加器的weighted_median函数库来有效地做到这一点[?]。本质上,我正在尝试做一些与已完成的非常相似的事情here.我不确定boost的累加器是正确的框架对于这个任务(如果不请建议!),但我还没有找到另一个O(n)加权中位数的现成实现。此时我的问题是是否有办法替换“for(inti=0;i附言我看过this所以问题,但事实并非如此真的很清楚如何将那里的答案变成可操作的解决方案。#include#include#include#include#includ

  9. c++ - 使用 boost::successive_shortest_path_nonnegative_weights 的最小成本最大流 - 2

    我需要使用计算流量网络的最小成本最大流量boost::successive_shortest_path_nonnegative_weights()BGL(v1_60_0)中可用的函数。如documentation中所述,thedirectedgraphG=(V,E)thatrepresentsthenetworkmustbeaugmentedtoincludethereverseedgeforeveryedgeinE.Thatis,theinputgraphshouldbeGin=(V,{EUET}).[...]TheCapacityEdgeMapargumentcapmustmape

  10. iphone - 核心数据 : Light-weight migration from xcdatamodel version n to n+5 - 2

    假设用户在他们的iPhone上安装了MyApp2.xcdatamodel,并且他们已经有一段时间没有升级他们的应用程序了。现在应用程序的当前版本使用MyApp7.xcdatamodel。轻量级迁移机制能否将数据平滑迁移到当前模型?我的假设是,只要MyApp3.xcdatamodel、MyApp4.xcdatamodel、MyApp5.xcdatamodel和MyApp6.xcdatamodel可用。谁能证实这个假设?提前致谢乔斯。 最佳答案 你的假设是正确的。只要您的项目中有所有模型,这就可以工作。

随机推荐