我有一个布局activity_main.xml
,它使用include
标记添加了另一个布局(login_screen.xml
signup_screen.xml
)。 使用include
标记添加的布局具有使用view
声明的视图组件。 该视图在它们各自的布局(login_screen.xml
signup_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>
如果在
标记上将android:layout_widts
设置为match_parent
,是否有效?
您现在实际上说的是“好的,让宽度匹配设置的任何约束”,但是没有任何约束要匹配。
注意:对于当前的XML,您可以使用LinearLayout
,并将Android:orient
设置为Vertical
-您目前没有指定任何约束。