I'm using the new Constraint
layout to build my layout. I need to have Button
that occupies almost the entire screen width and that was easy using constraints.
As you can see in the image I am setting the width to 0dp
(Any size), but the text don't stick at the center what's usually the normal for a button text.
I've tried: - set gravity to center - set textAlignment to center
Looks like this properties can't work with 0dp
width (Any size).
So I've tried to set the width to match_parent
using gravity center.
It's a little bit to the right.
Does any one know how to fix that behavior ?
Note that i'm using alpha4
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
XML code
<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 It was a bug in ConstraintLayout
alpha4.
UPDATE Google has released alpha5, the above code now Works. Release note