简体   繁体   English

如何在Android中的G +登录按钮中心设置textview

[英]How to set textview in center of G+ sign in button in Android

I am having G+ signinbutton in my code and its working fine for login. 我在我的代码中使用了G + signinbutton,它的登录工作正常。 I set it using below code in my xml 我在我的xml中使用下面的代码设置它

<com.google.android.gms.common.SignInButton
            android:id="@+id/btn_sign_in"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:textSize="15dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            />

What I have now is as below 我现在拥有的如下 在此输入图像描述

Now I want to set TextView to center of button. 现在我想将TextView设置为按钮的中心。 but, SignInButton doesn't seem to have android:gravity how can I set my TextView to center? 但是,SignInButton似乎没有android:gravity如何将TextView设置为居中?

@Karan - use below code , it's working for me. @Karan - 使用下面的code ,它对我有用。

    SignInButton signInButton = ((SignInButton) findViewById(R.id.btn_sign_in));


    for (int i = 0; i < signInButton.getChildCount(); i++) {
        View v = signInButton.getChildAt(i);

        if (v instanceof TextView) {
            TextView tv = (TextView) v;
            tv.setPadding(0, 0, 20, 0);
            return;
        }
    }
            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="@dimen/activity_horizontal_margin"
                android:layout_marginLeft="@dimen/small_margin"
                android:layout_marginRight="@dimen/small_margin"
                android:layout_marginTop="@dimen/activity_horizontal_margin"
                app:cardCornerRadius="@dimen/small_margin">

                <RelativeLayout
                    android:id="@+id/sign_google"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:padding="@dimen/text_padding">

                    <ImageButton
                        android:id="@+id/img"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@color/white"
                        android:src="@drawable/googleg_standard_color_18" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="@dimen/small_margin"
                        android:layout_toRightOf="@+id/img"
                        android:gravity="center"
                        android:text="@string/sign_in"
                        android:textColor="@color/black" />
                </RelativeLayout>
            </android.support.v7.widget.CardView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM