- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
虽然看起来很简单,但我做不到,但我希望两个按钮从侧面相互接触并水平居中,如下所示:
我在这个线程中尝试了答案:Center two buttons horizontally ,但它只与RelativeLayout有关,与ContrainstLayout无关
我也试过玩
app:layout_constraintHorizontal_chainStyle="spread"
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
style="@style/btnStyle"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:background="@color/btnTrue"
android:text="Button"
android:textColor="#ffffff"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
style="@style/btnStyle"
android:layout_height="wrap_content"
android:layout_marginEnd="56dp"
android:background="@color/btnFalse"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
最佳答案
这应该做的工作。
<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">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/button"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintHorizontal_chainStyle="packed"
关于android - 约束布局 : Center two buttons horizontally,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58929948/
这个问题在这里已经有了答案: Flexbox: Align between bottom and center? [duplicate] (2 个答案) 关闭 6 年前。 我正在尝试使用 flexb
用于居中元素的标签是 或 ? 我知道 或 标签不再使用,但哪一个是正确的? 我很迷惑。 Visual Studio 代码说 错了,但只有适用于 Microsoft Edge。 编辑:Microsof
我使用的是标准匹配用户界面和两台 iPad iOS6。问题是当我在第一台设备中创建新的匹配项时,第二台设备应该在我查看匹配用户界面时看到现有的匹配项,但事实并非如此。我确定我的代码是正确的。这是方法:
在我的项目的两个不同的类(都扩展 JFrame)中,我尝试这样做: header = new JLabel("Header"); header.setHorizontalAlignme
我已经在我的网站中实现了以下 jQuery 视差效果(取自 http://www.brandaiddesignco.com/insights/parallax-scrolling-made-easy/
每当我在我的 css 中居中文本时,它也会使图像居中。这是为什么?文本位于一个 div(“左”)内,图像位于第二个 div(“右”)内。这是 HTML - BANKS 还有
我现在有这段代码: 1 enE jk 5.6 mtE hp 6.4 hpE eb HML reE pm 514 hpE e
我只是制作一个页面或类似的东西。我想让我的按钮居中,但它不起作用。 我尝试用不同的方法将它居中,但它不起作用。看看代码。它有但它并没有将它置于整个页面的中心但只是喜欢......我不知道。照片:htt
我想知道如何将此页面中的字形居中,它们是使用@font-face 的图标字体,但即使在我将 text-align:center 应用于包含每个字形的 anchor 之后,它们也不是居中。 它们显示为左
考虑以下 HTML 片段, Hyperlink 如上所示,由于“...”标签,所有内容都将居中对齐。但是,我不希望带有“id=three”的 HTML 元素的中心对齐
我有以下 html: Site Map Privacy Policy Terms & Condi
我在将我正在处理的布局中的按钮上的文本居中时遇到问题。请查看下面的屏幕截图(在 eclipse 的“图形布局”选项卡中截取): 我不确定是什么原因造成的。我试着玩弄按钮的各个布局属性,但这没有任何效果
我正在尝试使用 Bootstrap 组装页脚。由于某些原因,尽管确保应用了 text-align: center;,但页脚链接看起来略微偏离中心。有没有办法确保所有文本元素确实正确对齐? HTML
我在使用 flexbox 工具 align-items:center; 时遇到了问题,它在中间并不完美,但文本、图标等的像素太高了……有人知道如何解决这个问题? screenshot how it l
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
GameKit 是否允许您以编程方式邀请特定的 Game Center friend 参加比赛,即不提供 GC ViewController?以下 handleInviteFromGameCenter
我有一个布局问题。 假设我有一个 RelativeLayout 出现在我的屏幕底部。在此,我想添加 2 个 TextView ,一个在中心,一个在顶部中心,一个在底部中心。 |------------
我有一个启动画面的 Activity layout.xml,它基本上显示了我想要的内容。但是如果我在更大或更小的屏幕设备上打开应用程序,它就不再居中了。 有没有办法在元素周围放置一个包装器并将其在屏幕
尝试了几十种方法后,我自己也想不出解决方案 #banner .slide { position: static; top: 0px; left: 0px; z-inde
您将如何修复以下传递过多参数的错误代码? void helper1(int p1, int p3, int p5, int p7, int p9, int p10) { // ... } void
我是一名优秀的程序员,十分优秀!