【发布时间】:2020-06-11 22:23:23
【问题描述】:
我正在使用新的Constraint 布局来构建我的布局。我需要Button,它几乎占据了整个屏幕宽度,并且很容易使用约束。
正如您在图片中看到的,我将宽度设置为 0dp(任何大小),但文本不会粘在中心,这通常是按钮文本的正常值。
我试过了: - 将重力设置为中心 - 将 textAlignment 设置为居中
看起来此属性不适用于 0dp 宽度(任何大小)。
所以我尝试使用重心将宽度设置为match_parent。
在右边一点。
有谁知道如何解决这种行为?
请注意,我使用的是 alpha4
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
XML 代码
<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:id="@+id/content_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="br.com.marmotex.ui.LoginActivityFragment"
tools:showIn="@layout/activity_login">
<Button
android:text="Log in"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/btLogin"
android:layout_marginTop="48dp"
app:layout_constraintTop_toBottomOf="@+id/textView6"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="@+id/content_login"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="@+id/content_login"
android:layout_marginLeft="16dp"
android:textColor="@android:color/white"
android:background="@color/BackgroundColor" />
</android.support.constraint.ConstraintLayout>
编辑这是ConstraintLayout alpha4 中的一个错误。
更新谷歌发布了alpha5,上面的代码现在可以工作了。 Release note
【问题讨论】:
标签: android android-constraintlayout