Я использую новый макет 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>
EDIT Это была ошибка в ConstraintLayout
alpha4.
ОБНОВЛЕНИЕ Компания Google выпустила alpha5, приведенный выше код теперь работает. Примечание к выпуску