【发布时间】:2020-11-21 10:35:50
【问题描述】:
我有一个布局 activity_main.xml,它使用 include 标签添加了另一个布局 (login_screen.xml signup_screen.xml)。使用include 标签添加的布局有一个使用View 声明的视图组件。该视图在它们各自的布局中是可见的(login_screen.xmlsignup_screen.xml),但在添加到activity_main.xml 时,View 变得不可见。我尝试将整个代码复制并粘贴到activity_main.xml 中,当时View 可见。
真正的问题是什么?有人可以帮帮我吗?
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/logo"/>
<TextView
android:id="@+id/app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"/>
<include
layout="@layout/login_screen"
android:id="@+id/login_screen"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<include
layout="@layout/signup_screen"
android:id="@+id/signup_screen"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/as_guest"/>
</androidx.constraintlayout.widget.ConstraintLayout>
login_screen.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="2dp"
android:layout_height="match_parent"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Username" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hintt="Password"/>
</androidx.constraintlayout.widget.ConstraintLayout>
signup_screen.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="2dp"
android:layout_height="match_parent"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Username" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hintt="Password"/>
</androidx.constraintlayout.widget.ConstraintLayout>
编辑:我已经删除了这里的所有约束以使其更易于阅读,在我的代码中,我已经正确设置了约束并且它是完美的。
【问题讨论】:
-
嗨,Kavin,我也遇到了类似的问题,能否请您更新一下您是如何解决的?