Rei*_*eid 5 android text-alignment android-layout google-signin
我正在使用以下代码将 google 登录按钮放在我的应用程序中。但是按钮中的文本偏离中心。我怎样才能使它居中?
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:visibility="visible"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp" />
Run Code Online (Sandbox Code Playgroud)
通过使用调试器和反编译的类代码进行检查,我注意到:
setStyle。它使用进程间绑定 API 从其他库中创建一些类,但我无法识别该类,也无法定位其反编译的类代码。因此,似乎在真正的按钮上放置了一些手动填充,在 G 图标的一侧。他们为什么要这样做,不知道。从上面可以看出,在按钮从 XML 膨胀后“修复”填充是非常安全的。我认为这在 RTL 的情况下也是安全的,因为带有图标的一侧的填充总是更大,我认为(或者我当然希望如此,如果这在 RTL 中损坏,请告诉我):
loginBinding!!.googButton.getChildAt(0)?.let {
val smaller = Math.min(it.paddingLeft, it.paddingRight)
it.setPadding(smaller, it.paddingTop, smaller, it.paddingBottom)
}
Run Code Online (Sandbox Code Playgroud)
那当然是 Kotlin。