Android支持存储库中提供的一种新类型布局,构建于灵活约束系统之上,标记视图相对于彼此的位置。
ConstraintLayout:将 TextView 的中心垂直对齐到有偏移的位置
我想在图形的一些众所周知的位置上创建标签。为此,我必须将“Enable”TextView 的垂直中心精确对齐到图形的第一条水平线
我有一个长屏幕,我使用 NestedScrollView 和 RecyclerView ,如下图所示: 正如你所看到的,我在屏幕底部有一个 commentConatiner 布局,当前用户看到我...
在ConstraintLayout中有一个具有相同宽度和高度的ImageView
如何让ImageView的宽度和高度等于父ConstraintLayout的宽度?所以它显示一个全宽的方形ImageView。 一般来说,如何将某个小部件的高度设置为等于
我在 Jetpack Compose 的基础知识方面遇到了一些问题。如果我像示例一那样堆叠列,则效果很好。在示例二中,高度修改器不起作用,任何连续的列都会...
我需要显示这样的信息框: 但我想要: 尽可能保持整个盒子的宽度最小(但包裹实际内容) 将其放在活动的左上角 数字应与
我在 1 个约束布局中有 10 个 TextView。我想要实现的是让约束布局有一定的高度,使所有 10 个文本视图看起来基本上都在我的背景之上...
在 ConstraintLayout 中对 Google 地图进行动画处理会使应用程序冻结
最近,我开始在我的应用程序中实现CostraintLayout,并且我有一个基于地图的应用程序需要地图动画。因此,我使用了强大的ConstraintSet来动画它,但是...
如何在 compose multiplatform for desk 中使用 ConstraintLayout
build.gradle.kts 我尝试添加这个依赖项 我想在 compose multiplatform for desk 中使用 ConstraintLayput,但不知道如何正确添加 compose 的 ConstraintLayout 的依赖
我确实有一个数据列表,是男性和女性类型。我已经在同一空间项目分隔符中填充了所有男性和女性数据的数据。但我在这里想要的是,我想要填充男性数据,例如 1d...
如何将焦点从 RowsSupportFragment 的行移动到下一个布局组件?
我正在使用 Android Leanback 库来创建电视应用程序。我有一个扩展 Fragment (即 RowsSupportFragment)的布局,其下方有一个按钮。所以,当我向下滚动到 lis 时...
在 ConstraintLayout 中对视图进行分组,将它们视为单个视图
我需要对 ConstraintLayout 中的一组视图应用一些约束。我想对这些视图进行分组并继续编辑,而 Android studio 中的布局设计器将它们视为单个视图。是
我正在尝试在 Android 中创建一个项目符号列表,其中项目符号与 TextView 中第一行的垂直中心对齐,如下所示: 单个项目符号/文本行的 XML 如下: 我正在尝试在 Android 中创建一个项目符号列表,其中项目符号与 TextView 中第一行的垂直中心对齐,如下所示: 单个项目符号/文本行的 XML 是这样的: <android.support.constraint.ConstraintLayout android:id="@+id/setup_intro_bullet_first_container" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"> <TextView android:id="@+id/setup_intro_bullet_first" style="@style/TextAppearance.AppCompat.Headline" android:layout_width="0dp" android:layout_height="wrap_content" android:text="@string/bullet" android:textColor="@color/colorAccent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/setup_intro_bullet_first_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="4dp" android:paddingTop="14dp" android:text="@string/setup_intro_benefit_notification" android:textColor="@android:color/white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toRightOf="@id/setup_intro_bullet_first" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> 这里我在 TextView 上使用填充来与项目符号对齐,但这不是解决方案,因为对齐方式在其他分辨率中不一致。我还尝试将项目符号字符放入文本字符串本身中,但第二行文本将位于项目符号下方,这不是我想要的。我想要一些关于如何实现这一目标的建议。 我想出的解决方案是创建一个圆圈Drawable并在ImageView中使用它。您可以定义 ImageView 的基线,这使我能够将其与 TextView 的基线正确对齐。这是圆 XML: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@color/colorAccent" /> </shape> 以及布局 XML: <ImageView android:id="@+id/setup_intro_bullet_first" style="@style/TextAppearance.AppCompat.Headline" android:layout_width="4dp" android:layout_height="4dp" android:baseline="7dp" android:src="@drawable/circle" app:layout_constraintBaseline_toBaselineOf="@+id/setup_intro_bullet_first_text" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toLeftOf="@+id/setup_intro_bullet_first_text" /> <TextView android:id="@+id/setup_intro_bullet_first_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="4dp" style="@style/TextAppearance.AppCompat.Subhead" android:text="@string/setup_intro_benefit_notification" android:textColor="@android:color/white" app:layout_constraintLeft_toRightOf="@id/setup_intro_bullet_first" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> 使用 app:layout_constraintBaseline_toBaselineOf 属性将“项目符号”视图的基线限制为文本视图的基线。 项目符号视图的限制: app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toLeftOf="@+id/setup_intro_bullet_first_text" app:layout_constraintBaseline_toBaselineOf="@+id/setup_intro_bullet_first_text" 您的文字: app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toRightOf="@id/setup_intro_bullet_first" app:layout_constraintRight_toRightOf="parent" app:layout_constraintBottom_toBottomOf="parent" 对于 Android Pie (28) 及以上版本,您可以直接使用 BulletSpan。对于以下版本,您可以使用 DrawableMarginSpan,但带有损坏的可绘制加项目符号 "\u2022"。 val yourSpan = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { BulletSpan( 8.px, ContextCompat.getColor(requireContext(), R.color.gray), 2.px, ) } else { DrawableMarginSpan(ContextCompat.getDrawable(requireContext(), R.drawable.ic_circle)!!, 20) } val yourString = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { "Just string" } else { "\u2022" + " Just string" } yourTextView.text = SpannableStringBuilder(yourString).apply { setSpan( yourSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE ) } 损坏的可绘制代码: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@color/gray"/> </shape>
如何避免在 Android 设备中低于特定高度的不可滚动布局中截断视图
我有一个无法滚动的约束布局,所有视图都必须始终可见。我遇到的问题是,对于高度为 1920 或更低的设备,UI 会变得非常拥挤,并且有些......
当条形高度与其父级之间有空间时,我想在图形条顶部保留一个标签,但希望当图形条接触其父级顶部和t时在图形条前面显示标签...
区别 `app:layout_constraintDimensionRatio="1:1"` 宽度和高度
app:layout_constraintDimensionRatio="H,1:1"有什么区别 和 app:layout_constraintDimensionRatio="W,1:1" 例如 app:layout_constraintDimensionRatio="...
layout_constraintDimensionRatio 的意外行为
据我所知,如果我在元素中使用 app:layout_constraintDimensionRatio="H,1:1 ,该元素的高度将被固定,然后宽度将适应与宽度相同的大小,但在 . ..
我有一个项目列表,我正在使用 RecyclerView 来显示它。 这是我的列表的一个示例: 我需要了解什么是更好地用于项目布局:RelativeLayout 或 ConstraintLayout 在我的...
如何为 ConstraintLayout 内的子视图赋予重力
我正在研究ConstraintLayout,我可以调整子视图,但无法从左到右对齐Textview。有没有办法让 Textview 从左到右对齐? 这是代码: <
我在显示没有 centerCrop 的横向图像时遇到问题。 我尝试了 PercentFramelayout,并以编程方式设置宽高比 像这样: laParams.percentLayoutInfo.aspectRatio = img.width.
Android 开发中将视图缩放到父级尺寸一定百分比的最佳方法是什么?
在我当前的项目中,有很多实例我想将视图缩放为其父容器的 1/8,因为我必须利用我可以使用的所有空间,因为我有很多功能...