问题描述
我已将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为什么)”左上方。
我引用了其他网站,视频。他们都有像this这样的可视按钮,但没有我。
解决方法
是的,我们在设计模式下看不到该图标,但在 运行该应用。
您的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" />
这是constraint-layout introduction
,尝试运行Gradle,这有时会触发设计重绘(如果您只是在未完全运行Gradle的情况下添加了Google库)