Android布局-相对与框架

发布于 2024-12-22 18:42:07 字数 98 浏览 6 评论 0原文

我有一个应用程序,我想实现一个布局,其中产品图像将位于背景中,顶部位于右下角,我想放置产品的价格,我想在左下角放置一个添加按钮。

我应该使用框架布局还是相对布局???

I have an application where I want to achieve a layout where the product image will be in the background and top of that to the right bottom, I want to place the price of the product and to the left bottom I want to place an add button.

Should I use frame layout or relative layout ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

咋地 2024-12-29 18:42:07

作为一个实际规则,我认为这取决于你。我个人倾向于使用RelativeLayouts,因为它们更灵活,但您可以使用其中任何一个实现相同的效果。

这篇 SO 文章更详细地解释了两种布局之间的性能差异:FrameLayout 与相对布局的覆盖

As a practical rule, I think it's up to you. I personally tend to use RelativeLayouts because they're more flexible, but you can achieve the same effect with either.

This SO post explains the performance differences between the two layouts in more detail: FrameLayout vs RelativeLayout for overlays

离笑几人歌 2024-12-29 18:42:07

相对布局:当兄弟姐妹或父母之间有关系时。

框架布局:当兄弟姐妹彼此独立放置并且仅依赖于父级时。

根据您的情况,您可以选择其中任何一个。

Relative layout: When you have relation between siblings or parent.

Frame layout: When siblings are placed independent of each other and are only dependent on parent.

Based on your situation, you can opt in of any of these.

長街聽風 2024-12-29 18:42:07

我的建议是,如果您对每个设备的背景都有特定的尺寸,那么请采用相对布局,并将背景设置为图像。因为在 RelativeLayout 中使用背景时,无论图像是否适合 RelativeLayout 的大小,它都会适合相对布局本身的大小。 (可以拉伸/像素化/未正确添加)

如果您不确定具体尺寸,您应该使用 FrameLayoutImageView 来处理 ScaleType,可以是centerCrop,它将以良好的形状适合布局。
对于 TextView,使用 layout_gravity,它将根据父布局处理位置。

My advice, If you have specific size for your background for each device, then go for relative layout, and set the background to your image. Because when using background in RelativeLayout, It'll fit the size of the relative layout itself, whether the image suits the size of the RelativeLayout or not. (Can be stretched/pixelated/Not properly added)

If you're not sure about specific size, you should use FrameLayout, with ImageView, that handles the ScaleType, which can be centerCrop, and it'll fit the layout in good shape.
And for the TextView, use layout_gravity, which will handle the position based on the parent layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文