当其中一个是 facebook LoginButton 时,如何使所有按钮具有相同的高度和宽度
How can I make all Buttons the same height and width when one of them is facebook LoginButton
我希望所有 Buttons
对我自动具有相同的高度和宽度。然而,Facebook Button
不会对 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>
使用这个:
<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>
为了您的 layout_weight
正常工作,您应该将每个 Buttons
的 layout_height
设置为 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" />
你可以通过让 fb sdks 登录按钮可见性消失并使用你自己的按钮来解决一些问题,就像你使用其他 3 一样。点击新按钮会在点击时触发 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>
我希望所有 Buttons
对我自动具有相同的高度和宽度。然而,Facebook Button
不会对 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>
使用这个:
<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>
为了您的 layout_weight
正常工作,您应该将每个 Buttons
的 layout_height
设置为 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" />
你可以通过让 fb sdks 登录按钮可见性消失并使用你自己的按钮来解决一些问题,就像你使用其他 3 一样。点击新按钮会在点击时触发 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>