我是否需要更改 xml 代码以支持所有屏幕尺寸的 Android 设备?

2024-02-04

我已经为不同的屏幕尺寸创建了布局,这是我的默认布局的 xml 代码 但所以任何人请告诉我应该做什么来支持任何屏幕尺寸的 Android 设备的布局。

我需要更改我的 xml 代码吗? 或者 只是我需要修改我的xml代码吗?

请告诉我,以便我解决我的问题

xlm

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Login"
            android:textSize="40sp"
            android:layout_marginTop="40dp"
            android:fontFamily="sans-serif-black"
            android:layout_gravity="center"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/nice"
            android:layout_marginTop="40dp"
            android:textSize="30sp"/>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/textInputLayoutUsername"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorEnabled="true"
            app:errorTextAppearance="@style/ErrorStyleNormal"
            android:padding="5dp"
            android:layout_marginTop="30dp"
            app:hintTextAppearance="@style/ErrorStyleNormal">
            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="25sp"
                android:hint="Username"
                />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/textInputLayoutPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            app:errorEnabled="true"
            app:passwordToggleEnabled="true"
            app:errorTextAppearance="@style/ErrorStyleNormal"
            android:layout_marginTop="20dp"
            app:hintTextAppearance="@style/ErrorStyleNormal"
            app:counterTextAppearance="@style/CounterStyleNormal">
            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:textSize="25sp"
                android:inputType="textPassword"/>
        </com.google.android.material.textfield.TextInputLayout>

        <TextView
            android:id="@+id/textViewForgotPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginEnd="15dp"
            android:layout_marginRight="15dp"
            android:text="@string/ForgotPassword"
            android:textSize="15sp" />

        <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            app:cardCornerRadius="25dp"
            android:elevation="5dp"
            android:padding="10dp"
            android:layout_marginTop="30dp">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="5dp">
                <ImageView
                    android:id="@+id/image"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:src="@drawable/ic_arrow_forward"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/Login"
                    android:layout_toEndOf="@+id/image"
                    android:layout_centerVertical="true"
                    android:textSize="25sp"
                    android:layout_marginRight="10dp"
                    android:layout_marginEnd="10dp"
                    android:fontFamily="sans-serif-black"
                    android:layout_toRightOf="@+id/image" />
            </RelativeLayout>
        </androidx.cardview.widget.CardView>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:text="@string/To_Join_With"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:textColor="@android:color/black"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:text="@string/Click_here"
            android:layout_gravity="center"
            android:textColor="@android:color/holo_blue_bright"/>
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

如果你想支持不同的屏幕尺寸,那么使用https://developer.android.com/reference/android/support/annotation/Dimension https://developer.android.com/reference/android/support/annotation/Dimension针对不同屏幕的不同尺寸的元素。如果您需要在不同屏幕上使用不同的元素布局,那么您可以为不同的屏幕尺寸创建不同的 xml 文件Android 不同屏幕尺寸的布局 https://stackoverflow.com/questions/44962692/android-layouts-for-different-screen-sizes

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我是否需要更改 xml 代码以支持所有屏幕尺寸的 Android 设备? 的相关文章

随机推荐

  • 如何在 C++ 中手动运行消息泵

    原问题 我们的应用程序使用 CSocket 它需要运行消息泵才能工作 目前 更改为另一个套接字实现是不切实际的 尽管这是我们希望在某个时刻结束的地方 该应用程序采用 Visual C 非托管 目前 我们使用 C NET 服务启动器来启动 C
  • 在 debian lenny 中安装 postgres 9.0 [关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 各位 我的系统有以下分布详细信息 lsb release a No LSB modules are available Distributor ID
  • 如何将 DataAdapter 与存储过程和参数一起使用

    我想使用 DataAdapter 填充 DataGridView 控件 但我不知道该怎么做 因为我正在使用带参数的存储过程 有人可以举个例子吗 我明白了 呵呵 protected DataTable RetrieveEmployeeSubI
  • 如何阻止滚动条移动我的页面?

    我通过将页面内容包装在包装器 div 中 然后将其放入样式表中 将页面内容居中 wrapper width 960px margin left auto margin right auto 问题是 每当内容增加并且出现垂直滚动条时 它就会取
  • 如何计算同一类的元素数量?

    我的页面中有一个主 div 其中包含特定的内容id 现在 该类中存在一些同一类的输入元素div 那么我如何计算这个类中这些元素的数量div using jQuery With jQuery您可以使用 main div specific cl
  • java中可以有多个堆吗?

    java中可以有多个堆吗 如果可能的话 那么在什么情况下会发生呢 已经存在多个内存区域 但只有一个 Java 堆 通常有 Java heap which might be broken into 伊甸园空间 幸存者空间 任期空间 用于小型直
  • UICollectionView 和 SwiftUI?

    如何使用 SwiftUI 创建方形项目网格 例如在 iOS 照片库中 我尝试了这种方法 但它不起作用 var body some View List cellModels in Color orange frame width 100 he
  • 并排均匀打印 2 个均匀填充的列表

    我使用以下代码生成 2 个列表 nameList 和gradeList nameList gradeList for row in soup find all tr name row select th strong grade row s
  • Eclipse 问题 - 启动错误:无法连接到远程虚拟机。连接超时

    我收到消息 启动错误 无法连接到远程虚拟机 连接超时 每次我在读取设备上调试我的应用程序时 我在 AndroidManifest 中添加了
  • 如何通过 Go SDK 流式传输 Docker 容器日志

    我正在为 Go 中的一些游戏服务器软件编写一个工具 名为sampctl https github com Southclaws sampctl主要功能是为服务器实例启动 Docker 容器 然后捕获从容器中发出的日志 稍微清理一下并将它们发
  • iOS7 标签栏图标太大

    似乎我在处理像图标这样简单的事情时遇到了困难 我正在构建一个仅适用于 iOS7 的应用程序 因此设备是视网膜显示屏 不包括 iPad 2 所以我为我的标签栏制作了一些 60 x 60 的图标 然而这些太大了 而且 30 x 30 有点像素化
  • 从自定义 SurfaceView 获取位图

    我在一个扩展表面视图并实现可运行的类中有这段代码 我能够使用该类基本上允许您使用不同的颜色等绘制到画布上 我正在尝试找到一种方法 该方法允许我在绘制图像后保存图像 这就是方法 无论我做什么 我都会得到一张没有任何内容的黑色图像 有任何想法吗
  • Java - 字符缓冲区问题

    我有一个 1 99 GB 的字符文件 现在 我想从该文件中随机提取数百万个子序列 例如从位置 90 到 190 10 到 110 50000 到 50100 等 每个子序列长 100 个字符 我通常使用 FileChannel channe
  • 如何使用多线程进行zlib压缩(相同输入源)

    我的目标是在并行线程中压缩同一源的数据 我已经定义了列表中的作业 这些作业具有读取信息 每个作业中 500kb 1MB 我的压缩器线程将使用 ZLIB 压缩每个块的数据并将其存储在相应作业的 outbuf 中 现在 我想合并所有这些并创建一
  • 如何检测用户是否在浏览器中启用了全屏

    当用户在 Chrome 或 FireFox 中启用全屏时 是否会触发一些 JavaScript 事件 我有 WebGL 应用程序 画布宽度和高度设置为一定大小 当用户启用全屏时 我想调整其大小 如果没有这样的事件 我是否应该开始研究用画布填
  • 如何在 PyQt5 中使用全局键盘快捷键显示 QMenu?

    我试图通过热键 例如 F1 显示 QMenu 实例PyQt5 然后我找到了这个包keyboard https pypi org project keyboard 尝试像这样使用它 keyboard add hotkey F1 self sh
  • 将 HTML 表转换为 JSON

    我正在尝试将通过 BeautifulSoup 提取的表转换为 JSON 到目前为止 我已经成功隔离了所有行 但我不确定如何使用这里的数据 任何建议将非常感激 tr td strong Balance strong td td strong
  • WP8.1后退按钮退出应用程序

    上次我针对 Windows Phone 进行开发时使用的是版本 8 现在我正在使用 8 1 也许这是微软的一项新功能 但是当我按下手机上的后退按钮时 无论我对应用程序的了解有多深 应用程序都会最小化 这真的很烦人 有什么我可以做的吗 提前谢
  • 自动填充子图

    我正在编写一个 python 脚本 该脚本将 1 获取每个子图的 y 值列表 以针对一组通用的 x 值进行绘制 2 将每个子图设为散点图并放置将其放置在子图网格中的适当位置 并且 3 针对不同大小的子图网格完成这些任务 第三个语句的意思是
  • 我是否需要更改 xml 代码以支持所有屏幕尺寸的 Android 设备?

    我已经为不同的屏幕尺寸创建了布局 这是我的默认布局的 xml 代码 但所以任何人请告诉我应该做什么来支持任何屏幕尺寸的 Android 设备的布局 我需要更改我的 xml 代码吗 或者 只是我需要修改我的xml代码吗 请告诉我 以便我解决我