1

Так как заголовок говорит; У меня возникают проблемы с выравниванием моих социальных кнопок входа в горизонтальном LinearLayout. Я пробовал это с помощью обычных кнопок, и они идеально выравниваются, но всякий раз, когда я переключаюсь на кнопки Facebook и Google, они почему-то неправильно выравнивают.Кнопки социальных (Google и Facebook) не выровнены по горизонтали LinearLayout

Это то, что они выглядят, как с точки зрения дизайна:

enter image description here

А это мой XML-код:

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <com.facebook.login.widget.LoginButton 
       android:id="@+id/facebookButton" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center_horizontal" 
       android:paddingTop="10dp" 
       android:paddingBottom="10dp" 
       android:layout_weight="1" 
       android:layout_marginStart="16dp" /> 


      <com.google.android.gms.common.SignInButton 
       android:id="@+id/googleButton" 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center_horizontal" 
       android:layout_weight="1" 
       android:layout_marginEnd="13dp"/> 


     </LinearLayout> 

ответ

1

Попробуйте положить андроида: layout_gravity = "центр" в вашем LinearLayout.

+0

Возможно, только андроид: gravity = "center"? – Ekalips

+0

Да, на самом деле очень глупая ошибка. Все, что мне нужно было сделать, это изменить андроид: layout_gravity = "centre_horizontally" to = "center" - спасибо! – AndroidDevBro

1
<LinearLayout android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:gravity="center" 
    android:weightSum="2" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <com.facebook.login.widget.LoginButton 
     android:id="@+id/facebookButton" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:layout_weight="1" 
     android:layout_marginStart="16dp" /> 


    <com.google.android.gms.common.SignInButton 
     android:id="@+id/googleButton" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:layout_marginEnd="13dp"/> 


</LinearLayout>