【问题标题】:Are there any limitations on how we use layouts in android?我们如何在android中使用布局有什么限制吗?
【发布时间】:2017-03-07 10:28:07
【问题描述】:

我为我的应用创建了一个好看的布局,但我在线性布局中使用了相对布局(根据我的需要)。

这样好吗?我的团队伙伴告诉我,这不符合 android 指南,这会使应用在搜索中失败。

所以基本上,对于我们应该如何使用布局以及当应用在 Play 商店中时 Google 是否会监控这些代码,是否有任何限制

这是代码(修改后必须放入)

           <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/bio2"
                    android:layout_below="@+id/bio1"
                    android:orientation="horizontal"
                    android:layout_marginTop="15dp">
                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">

                                        <TextView
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"
                                            android:text="Sagar Vakkala"
                                            android:textStyle="bold"
                                            android:textColor="#000"
                                            android:id="@+id/namebio"
                                            android:layout_marginLeft="15sp"
                                            />
                                        <TextView
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:layout_below="@id/namebio"
                                            android:textStyle="normal"
                                            android:text="From Delhi to Chennai in a whiff :)"
                                            android:textColor="#000"
                                            android:layout_marginLeft="15dp"
                                            android:layout_marginTop="10dp"
                                            />


                            </RelativeLayout>




                </LinearLayout>

【问题讨论】:

  • 没有这样的限制..
  • 嵌套布局不利于性能。您可以利用RelativeLayout relativity 并摆脱容器。
  • 我认为他们不会根据布局静态文件对应用程序进行排名,尽管它们可能会超过性能排名。别担心。随着时间的推移,您将学习如何优化布局并摆脱无用的 ViewGroup。
  • 你的队友完全错了:)
  • 还是没有得到明确的答案:(

标签: android xml user-interface user-experience design-guidelines


【解决方案1】:

不,对于您添加的布局数量没有任何限制,也没有您在构建 Android 应用时必须遵循的任何限制。然而,谷歌确实监控你的应用程序,放在 PlayStore 上。

【讨论】:

  • google 建议使用尽可能扁平的布局,即层次较少,但仅出于性能考虑,以使应用程序稍微快一些。如果您想要并且感觉活动运行得足够快,您可以拥有 100 级布局。见developer.android.com/training/improving-layouts/…
【解决方案2】:

在您的情况下,您可以改用 ConstraintLayout。

查看文档: https://developer.android.com/training/constraint-layout/index.html

【讨论】:

  • 感谢您向我介绍该布局,但是如果这种布局已经存在,那么为什么人们仍然选择相对布局?
  • 因为 ConstraintLayout 是 Android 最新的 Layout 而人们并不知道。
【解决方案3】:

尝试减少另一层或两层内的嵌套线性布局是可以的,如果您尝试提出有点复杂的 UI,最好扩展 android ViewGroup 类并创建自己的视图

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    相关资源
    最近更新 更多