Search code examples
androidxmlbuttonevenly

How can I make all Buttons the same height and width when one of them is facebook LoginButton


I want all Buttons to me the same height and width automatically. The Facebook Button however does not react to android:layout_weight="1", and as I did in the code setting the padding for it will not work consistently.

enter image description here

    <?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.port.android.ui.ActivityMain">

    <TextView
        android:id="@+id/first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:textAlignment="center"
        app:layout_marginTopPercent="20%"
        app:layout_widthPercent="70%"
        app:layout_heightPercent="10%"
        android:gravity="center"
        android:text="Some text about login" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/buttons"
        android:layout_below="@+id/first"
        android:layout_above="@+id/second"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <com.facebook.login.widget.LoginButton
            android:id="@+id/login_with_facebook"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="15dp"
            android:paddingBottom="15dp"
            android:layout_weight="1"
            android:text="@string/login_with_facebook" />

        <Button
            android:id="@+id/login_with_google"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/google_button_press"
            android:text="@string/login_with_google" />

        <Button
            android:id="@+id/login_with_twitter"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/login_with_twitter" />

        <Button
            android:id="@+id/login_with_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/login_with_password" />
    </LinearLayout>

    <TextView
        android:id="@+id/second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        app:layout_widthPercent="70%"
        app:layout_marginBottomPercent="5%"
        app:layout_heightPercent="15%"
        android:gravity="center"
        android:text="Some more text about login" />
</android.support.percent.PercentRelativeLayout>

Solution

  • U can make some work around by making fb sdks login button visibility gone and taking ur own button just like u have used other 3. And onclick of new button fire the FB login buttons on click

    <FrameLayout
                android:id="@+id/FrameLayout1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal">
    
                <com.facebook.login.widget.LoginButton
                    android:id="@+id/fbLogin"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="gone"/>
    
                <TextView
                    android:id="@+id/txtFBLogin"
                    android:layout_width="300dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:background="@drawable/signup_fb_bg"
                    android:drawableLeft="@drawable/ic_facebook"
                    android:drawablePadding="-20dp"
                    android:gravity="center"
                    android:padding="@dimen/dimen_7dp"
                    android:text=""
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/dimen_18sp"
                    android:textStyle="bold"/>
    
    </FrameLayout>