gpt4 book ai didi

android - 创建基于百分比的布局

转载 作者:行者123 更新时间:2023-11-29 00:33:33 25 4
gpt4 key购买 nike

我正在尝试做我的第一个应用。

我正在做一个包含四行的布局。第一行有一个标题(10% 高),第二行有两张图片(40% 高),第三行有两张图片(40% 高),第四行有一个按钮(10% 高)。

现在,我正在使用垂直方向的线性布局。使用权重总和和权重,我在每一行上都有正确的比例。

但是,如果我在第二行和第三行中使用线性布局权重,则会收到有关嵌套权重和性能不佳的警告。我了解糟糕的性能问题,但我不知道没有它们如何解决我的问题。

我需要每张图片都是其父级宽度的 50%。

感谢您的帮助。

编辑:这是我想要完成的快速模型 https://dl.dropbox.com/u/252856/androidlayout.jpg

最佳答案

在您的特定情况下,您可以使两个 ImageViews 占据父级宽度的 50%,而无需使用像这样的 block 的权重:

<RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" 
android:layout_weight="your_value">
<View android:id="@+id/anchor" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_centerHorizontal="true"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_alignParentLeft="true"
android:layout_alignRight="@id/anchor" />
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_alignParentRight="true"
android:layout_alignLeft="@id/anchor" />
</RelativeLayout>

关于android - 创建基于百分比的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13975261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com