gpt4 book ai didi

android - 使用嵌套在 标签中的 - Android

转载 作者:行者123 更新时间:2023-12-05 00:00:44 24 4
gpt4 key购买 nike

我有两个可重复使用的布局,header_item.xml 和 custom_view.xml(使用 merge 标记)。custom_view 始终在 LinearLayout 标记内使用。

我想在这个 custom_view 中包含 header_item,但 Android Studio 给我这个错误消息:“无法解析类包含”。

奇怪的是,我可以运行该应用程序,而且似乎运行良好。但我不确定这是 Android Studio 问题还是我不​​应该在 merge 标签内使用 include

这是 xml 文件:

标题项:

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Header"
android:textStyle="bold"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

和自定义 View :

<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:parentTag="android.widget.LinearLayout">

<include layout="@layout/header_item" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text from custom view" />

</merge>

最佳答案

<include> <merge> 内部工作得很好,但是 Android Studio 无法处理这种情况,并且会显示 Cannot resolve class include标签上的错误。也许将来会修复。

关于android - 使用嵌套在 <merge> 标签中的 <include> - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70466047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com