0

我希望所有人都Buttons自动具有相同的高度和宽度。然而,FacebookButton不会对 做出反应android:layout_weight="1",并且正如我在代码设置中所做的那样padding,它不会始终如一地工作。

在此处输入图像描述

    <?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>
4

3 回答 3

1

您可以通过使 fb sdks 登录按钮可见性消失并使用您自己的按钮来解决一些问题,就像您使用其他 3 一样。新按钮的 onclick 会在单击时触发 FB 登录按钮

<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>
于 2016-10-21T10:02:03.833 回答
0

使用这个:

<LinearLayout
    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="0dp"
        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="0dp"
        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="0dp"
        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="0dp"
        android:layout_weight="1"
        android:text="@string/login_with_password" />
</LinearLayout>
于 2016-10-21T09:50:42.550 回答
0

为了使您layout_weight正常工作,您应该将layout_height每个设置Buttons为 0。


<com.facebook.login.widget.LoginButton
            android:id="@+id/login_with_facebook"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            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="0dp"
            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="0dp"
            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="0dp"
            android:layout_weight="1"
            android:text="@string/login_with_password" />
于 2016-10-21T09:52:08.313 回答