为什么我看不到谷歌登录按钮?



我已将Google登录链接到我的"JoinActivity"。像这样。。。

activity_join.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".JoinActivity">
<!--    this line-->
<com.google.android.gms.common.SignInButton
android:id="@+id/btn.google"
android:layout_width="200dp"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>

但是,我在"设计"选项卡上看不到任何"视觉"按钮,左上角只有"200dp线性按钮"(因为它的宽度值是200dp。它没有高度值。idk why(。

我参考了其他网站,视频。他们都有这样的可视按钮,但我没有。

是的,我们在设计模式下看不到图标,但当运行应用程序。

您的XML有一个错误:

此视图不受约束。它只有设计时的职位,所以它将在运行时跳转到(0,0(,除非添加约束

要使其正常工作,我们必须添加水平和垂直的约束。

<com.google.android.gms.common.SignInButton
android:id="@+id/btn.google"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

这是限制布局介绍

尝试运行Gradle,这有时会触发设计重新绘制(如果您刚刚添加了谷歌库,但没有完全运行Gradle(

最新更新