android-constraintlayout 相关问题

Android支持存储库中提供的一种新类型布局,构建于灵活约束系统之上,标记视图相对于彼此的位置。

如何在约束布局中将一个视图与另一个视图的中心对齐

在上图中,我必须将这些点(它们只是 XML 中的空视图)与其上方图标的中心对齐 下面的代码是我的回收器视图,其中包含视图的 在上图中,我必须将这些点(它们只是 XML 中的空视图)与其上方图标的中心对齐 下面的代码是我的回收器视图,其中包含视图的 <androidx.core.widget.NestedScrollView android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/itemImage"> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/nestedRecyclerView"/> </androidx.core.widget.NestedScrollView> 上面的代码是图标的 <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/itemImage" android:src="@drawable/ic_glucose" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent"/> 现在我需要将“NestedScrollView”与“ImageView”的中心对齐,以便点可以与图标的中心对齐。 如果我设置 app:layout_constraintLeft_toLeftOf="nestedScrollView" 它将完全向左对齐,但我希望它与图标的中心对齐 我该怎么做,请提出建议 不可能直接将 NestedScrollView 的左侧对齐到 ImageView 的中心,但有一种方法。 您可以将空视图与 ImageView 的中心对齐(ImageView 的从右到右,从左到左)。然后,您的 NestedScrollView 可以简单地与这个居中的 View 对齐,并且通过将 RecyclerView 与 NestedScrollView 的左侧对齐,您将获得所需的结果。 只需将约束指定为要在中心对齐另一个视图的同一视图的顶部到顶部和底部到底部。 <TextView android:id="@+id/tvPrintKOT" **app:layout_constraintTop_toTopOf="@+id/rgKOT" app:layout_constraintBottom_toBottomOf="@+id/rgKOT"** app:layout_constraintStart_toStartOf="parent" /> <RadioGroup **android:id="@+id/rgKOT"** android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintStart_toEndOf="@+id/tvPrintKOT" app:layout_constraintTop_toBottomOf="@+id/tvTitle" android:orientation="horizontal" > </RadioGroup>

回答 2 投票 0

使用 Compose ConstraintLayout 时如何处理丢失/“消失”的视图

我正在尝试使用 Jetpack Compose ConstraintLayout,如果所有视图都可见,则说明效果很好。 但如果缺少其中一个视图,沙堡就会倒塌。 例如,如果一场比赛...

回答 4 投票 0

根据大小水平显示两个或多个文本 Jetpack compose Android

我需要逐行显示多个文本,类似于段落。我想要的实现类似于以下内容: 我当前的实现如下所示: 这是代码, 约束Lay...

回答 1 投票 0

如何在 android studio 中使用 androidx.constraintLayout 文本修复灰屏

我正在学习android开发 我的 android studio 的设计视图有这个问题,显示灰色背景,中间有 androidx.constraintLayout.constraintLayout 文本 XML 设计

回答 2 投票 0

Jetpack Compose 约束布局。预览中的限制发生了变化

问题演示 - https://i.stack.imgur.com/vjjL3.png 在预览中,使用约束布局时,预览窗口中的约束会用偏移量指示。怎么会这样……

回答 1 投票 0

以编程方式使用 ConstraintSet 将 Button 添加到 ConstrainLayout

大家好。 我尝试以编程方式将按钮添加到 ConstraintLayout 并将 ConstraintSet 设置为此类按钮。 当我尝试从布局中关闭约束集时,问题就出现了...

回答 1 投票 0

如何将 Flow 小部件在 ConstraintLayout 中居中?

我目前面临将 Flow 小部件在 ConstraintLayout 中居中的问题。 Flow 小部件包含两个子 TextView 元素,我希望整个 Flow 水平居中...

回答 1 投票 0

扩展 SwitchMaterial 和 NPE 发生

我正在尝试在Android中自定义SwitchMaterial类,就像这样 类 TipSwitchMaterial @JvmOverloads 构造函数( 上下文:上下文, attrs:属性集? = 空, defStyleAttr: Int =

回答 2 投票 0

滚动 Android TV 时如何阻止 RecyclerView 与 TextView 重叠

我有一个 Android TV 应用程序,它在 TextView 下方有一个 RecyclerView。一切看起来都很棒,直到我单击第三个项目,导致 RecyclerView 覆盖 TextView。 我有一个 Android TV 应用程序,它在 TextView 下方有一个 RecyclerView。一切看起来都很棒,直到我单击第三个项目,导致 RecyclerView 覆盖 TextView。 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="false" android:focusableInTouchMode="false" android:keepScreenOn="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:clipToPadding="false" android:clipChildren="false" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"> <TextView android:id="@+id/dateTV" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" android:layout_marginStart="@dimen/homeHorizontalMargin" android:paddingBottom="20dp" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_below="@id/dateTV" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_marginHorizontal="@dimen/epgRVHorizontalMargin" android:focusable="false" android:focusableInTouchMode="false" android:descendantFocusability="afterDescendants" /> </RelativeLayout> </androidx.constraintlayout.widget.ConstraintLayout> 如何阻止 RecyclerView 与 TextView 重叠? 您的 RecyclerView 父布局具有以下属性 android:clipToPadding="false" android:clipChildren="false" 因此,当您滚动RecyclerView时,它将与布局中的其他视图重叠。 您可以将其删除。为什么在这里使用这个属性有什么具体原因要在屏幕上设计其他视图吗? 或者您有 ConstraintLayout 作为根布局,那么为什么您再次添加 RelativeLayout 并将 RecyclerView 放入此布局中。 您可以像下面这样设计您的 XML 布局 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="false" android:focusableInTouchMode="false" android:keepScreenOn="true"> <TextView android:id="@+id/dateTV" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/homeHorizontalMargin" android:paddingBottom="20dp" android:textSize="18sp" app:layout_constraintTop_toTopOf="parent" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_below="@id/dateTV" android:layout_marginHorizontal="@dimen/epgRVHorizontalMargin" android:layout_marginTop="20dp" android:descendantFocusability="afterDescendants" android:focusable="false" android:focusableInTouchMode="false" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@id/dateTV" /> </androidx.constraintlayout.widget.ConstraintLayout>

回答 1 投票 0

如果设备语言为阿拉伯语,布局设计会发生变化

我在 Android 应用程序中遇到与自定义对话框相关的布局问题。在英语模式下,对话框可以完美显示,宽度设置为 match_parent。然而,当切换到阿拉伯语模式时...

回答 1 投票 0

ConstraintLayout 不放置视图,所有内容都堆叠在左上角

我正在尝试使用 ConstraintLayout 但每个视图都堆叠在左上角。无论我如何尝试,即使存在约束,我也无法使图像视图位于右侧

回答 1 投票 0

以编程方式添加约束

具有约束布局的布局定义中使用的以下 XML 指令的 java 代码翻译是什么? 应用程序:layout_constraintBottom_toBottomOf =“@+id / Button1” 应用程序:

回答 2 投票 0

ConstraintLayout 中的两个水平旋转器

我试图在 ConstraintLayout 中将两个微调器彼此相邻放置。但是,当我在真实设备上运行该应用程序时,其中一个旋转器会扩展到屏幕末端并隐藏另一个旋转器...

回答 1 投票 0

将 ConstraintLayout 内的元素组水平居中

我必须在约束布局内放置三个组件:图像,并在图像右侧放置两个文本视图。两个文本视图均沿图像居中。 他们在一起...

回答 1 投票 0

ConstraintLayout:将 TextView 的中心垂直对齐到有偏移的位置

我想在图形的一些众所周知的位置上创建标签。为此,我必须将“Enable”TextView 的垂直中心精确对齐到图形的第一条水平线

回答 1 投票 0

在用户滚动时更改视图的位置

我有一个长屏幕,我使用 NestedScrollView 和 RecyclerView ,如下图所示: 正如你所看到的,我在屏幕底部有一个 commentConatiner 布局,当前用户看到我...

回答 1 投票 0

在ConstraintLayout中有一个具有相同宽度和高度的ImageView

如何让ImageView的宽度和高度等于父ConstraintLayout的宽度?所以它显示一个全宽的方形ImageView。 一般来说,如何将某个小部件的高度设置为等于

回答 2 投票 0

Jetpack Compose 中的堆叠列

我在 Jetpack Compose 的基础知识方面遇到了一些问题。如果我像示例一那样堆叠列,则效果很好。在示例二中,高度修改器不起作用,任何连续的列都会...

回答 2 投票 0

保持 ConstraintLayout 的最小宽度

我需要显示这样的信息框: 但我想要: 尽可能保持整个盒子的宽度最小(但包裹实际内容) 将其放在活动的左上角 数字应与

回答 1 投票 0

具有透明度和标高的约束布局

我在 1 个约束布局中有 10 个 TextView。我想要实现的是让约束布局有一定的高度,使所有 10 个文本视图看起来基本上都在我的背景之上...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.