android – 不同屏幕尺寸的约束布局

android – 不同屏幕尺寸的约束布局,第1张

概述如何使用约束布局自动调整两个小部件之间的间隙或边距,用于不同的屏幕尺寸,例如ios.不同的屏幕尺寸可以是4.7,5.0或5.5.所有这些设备都从维度正常中选择维度,所以有没有其他方法可以自动调整两个小部件之间的边距 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns 如何使用约束布局自动调整两个小部件之间的间隙或边距,用于不同的屏幕尺寸,例如ios.不同的屏幕尺寸可以是4.7,5.0或5.5.所有这些设备都从维度正常中选择维度,所以有没有其他方法可以自动调整两个小部件之间的边距

<?xml version="1.0" enCoding="utf-8"?> <androID.support.constraint.ConstraintLayout  xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"><ImageVIEw    androID:ID="@+ID/imageVIEw"    androID:layout_wIDth="0dp"    androID:layout_height="190dp"    androID:layout_marginleft="16dp"    androID:layout_marginStart="0dp"    androID:layout_margintop="0dp"    androID:contentDescription="dummy"    androID:scaleType="centerCrop"    androID:src="@drawable/lion"    app:layout_constraintBottom_creator="1"    app:layout_constraintEnd_toEndOf="parent"    app:layout_constraintHorizontal_bias="0.0"    app:layout_constraintleft_creator="1"    app:layout_constraintleft_toleftOf="parent"    app:layout_constraintRight_creator="1"    app:layout_constraintStart_toStartOf="parent"    app:layout_constrainttop_creator="1"    app:layout_constrainttop_totopOf="parent"    tools:layout_editor_absoluteX="16dp"    tools:layout_editor_absoluteY="16dp" /><androID.support.design.Widget.TabLayout    androID:ID="@+ID/tabLayout"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:layout_margintop="0dp"    app:layout_constrainttop_toBottomOf="@+ID/imageVIEw"    tools:layout_editor_absoluteX="8dp">    <androID.support.design.Widget.TabItem        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="abc" />    <androID.support.design.Widget.TabItem        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="xyz" /></androID.support.design.Widget.TabLayout><androID.support.design.Widget.TextinputLayout    androID:ID="@+ID/til_et_email"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:layout_marginEnd="24dp"    androID:layout_marginStart="24dp"    androID:layout_margintop="16dp"    app:layout_constraintEnd_toEndOf="parent"    app:layout_constraintStart_toStartOf="parent"    app:layout_constrainttop_toBottomOf="@+ID/tabLayout">    <androID.support.design.Widget.TextinputEditText        androID:ID="@+ID/et_email"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:gravity="center_horizontal"        androID:hint="@string/et_email_hint" /></androID.support.design.Widget.TextinputLayout><androID.support.design.Widget.TextinputLayout    androID:ID="@+ID/til_password"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:layout_marginEnd="24dp"    androID:layout_marginStart="24dp"    androID:layout_margintop="0dp"    app:layout_constraintEnd_toEndOf="parent"    app:layout_constraintStart_toStartOf="parent"    app:layout_constrainttop_toBottomOf="@+ID/til_et_email">    <EditText        androID:ID="@+ID/et_password"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:gravity="center_horizontal"        androID:hint="@string/et_password_hint" /></androID.support.design.Widget.TextinputLayout><button    androID:ID="@+ID/button"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:layout_marginEnd="24dp"    androID:layout_marginStart="24dp"    androID:layout_margintop="16dp"    androID:text="@string/bt_sign_in"    app:layout_constraintEnd_toEndOf="@+ID/til_password"    app:layout_constraintStart_toStartOf="@+ID/til_password"    app:layout_constrainttop_toBottomOf="@+ID/til_password"    tools:layout_editor_absoluteY="403dp" /><TextVIEw    androID:ID="@+ID/tv_forgot_password"    androID:layout_wIDth="0dp"    androID:layout_height="wrap_content"    androID:layout_marginEnd="8dp"    androID:layout_marginStart="8dp"    androID:layout_margintop="8dp"    androID:autoSizeMaxTextSize="41sp"    androID:autoSizeMinTextSize="17sp"    androID:autoSizeStepGranularity="2sp"    androID:autoSizeTextType="uniform"    androID:gravity="center"    androID:text="@string/tv_forgot_password"    app:layout_constraintEnd_toEndOf="parent"    app:layout_constraintStart_toStartOf="parent"    app:layout_constrainttop_toBottomOf="@+ID/button" />

在上面的部分中,我将边缘值设置为硬编码.所以,如果我在5.0屏幕尺寸上运行代码就可以了.但是,如果我在5.5屏幕尺寸上运行它,而不是调整边距,它会在底部留下空白区域.

解决方法 使用“指南”约束可根据不同的屏幕大小为视图提供百分比.

<androID.support.constraint.GuIDeline                androID:ID="@+ID/top_guIDeline"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal"                app:layout_constraintGuIDe_percent="0.09" />

请参阅以下谷歌链接.
https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

总结

以上是内存溢出为你收集整理的android – 不同屏幕尺寸的约束布局全部内容,希望文章能够帮你解决android – 不同屏幕尺寸的约束布局所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1126055.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存