簡體   English   中英

如何在Android中的G +登錄按鈕中心設置textview

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

我在我的代碼中使用了G + signinbutton,它的登錄工作正常。 我在我的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"
            />

我現在擁有的如下 在此輸入圖像描述

現在我想將TextView設置為按鈕的中心。 但是,SignInButton似乎沒有android:gravity如何將TextView設置為居中?

@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