android / codelab-constraint-layout

Constraint Layout Codelab
https://codelabs.developers.google.com/codelabs/constraint-layout/
Apache License 2.0
471 stars 242 forks source link

2.0.0-beta2 - Widget.Button gravity #66

Open GuilhE opened 5 years ago

GuilhE commented 5 years ago

My button inherits from .../platforms/android-28/data/res/values/styles.xml:

<style name="Widget.Button">
        <item name="background">@drawable/btn_default</item>
        <item name="focusable">true</item>
        <item name="clickable">true</item>
        <item name="textAppearance">?attr/textAppearanceSmallInverse</item>
        <item name="textColor">@color/primary_text_light</item>
        <item name="gravity">center_vertical|center_horizontal</item>
</style>

My changes are:

<style name="AppTheme.Button" parent="android:Widget.Button">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">@dimen/default_btn_height</item>
        <item name="android:foreground">?android:selectableItemBackground</item>
        <item name="android:background">@android:color/transparent</item>
        <item name="android:fontFamily">@font/gotham_bold</item>
        <item name="android:textAllCaps">true</item>
</style>
<style name="AppTheme.Button.OutlineBlue" parent="AppTheme.Button">
        <item name="android:background">@drawable/bg_outline_blue</item>
        <item name="android:textColor">@color/colorPrimary</item>
</style>

Finally using the AppTheme.Button.OutlineBlue

It seems that gravity = center_vertical|center_horizontal is not being respected: Screenshot 2019-06-25 at 16 25 07

If I lower back to beta1 its ok:

Screenshot 2019-06-25 at 16 29 39

<Button
        style="@style/AppTheme.Button.OutlineBlue"
        android:text="@string/btn_all"
        android:layout_marginTop="10dp"
        android:layout_marginStart="35dp"
        android:layout_marginEnd="35dp"
        android:visibility="@{viewModel...}"
        android:onClick="@{viewModel...}"
        app:layout_constraintTop_toBottomOf="@id/const_container"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>
GuilhE commented 5 years ago

If I use android:layout_width="0dp" it fixes the problem (ConstraintLayout as parent). But, until 2.0.0-beta2 it worked. I usually inside ConstraintLayout use 0dp but in this case, I forgot.

Yesamwamuo commented 5 years ago

Same issue in my project.