工具:listheader不'尽管工具不起作用:listitem起作用



我有一个片段布局,其中包含以下代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BlankFragment">
<ListView
android:id="@+id/blankList"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listheader="@layout/menu_header"
tools:listitem="@layout/fragment_item" />
</FrameLayout>

我的fragment_item包含以下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal"
android:background="#f0f0f0">
<ImageView
android:id="@+id/image_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:paddingBottom="3dp"/>
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/menu_article_text_size"
android:layout_marginStart="16dp"
android:textAppearance="?attr/textAppearanceListItem" />
</LinearLayout>

我的菜单标头包含以下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="12dp"
android:id="@+id/view2"
app:cardCornerRadius="40dp"
android:layout_centerHorizontal="true">
<ImageView
android:layout_height="80dp"
android:layout_width="match_parent"
android:id="@+id/imageView1"
android:src="@drawable/ic_launcher_background"
android:scaleType="centerCrop"/>
</android.support.v7.widget.CardView>
</LinearLayout>

我的问题是,出于某种原因,当我运行应用程序时,片段会工作,列表会出现,其中的项目也很好,但标题根本不存在。

有人帮忙吗?

*重要事实*在预览中,它确实有效,但当我运行时它不起作用

我的问题是,由于某种原因,当我运行应用程序时工作,列表会出现,其中的项目也很好,但标题根本不存在。

  • 重要事实*在预览中,它确实有效,但当我运行它时就不行了

=>看起来您误解了tools属性。这些是设计时属性,意味着它在设计布局时很有用。是的,这些不适用于运行时,所以很明显它不会出现在应用程序中。

通过给您举一个android:text="Hello Worldtools:text="Hello World"的例子来澄清这一点。您应该使用工具属性将演示/测试数据放在布局中,这样用户就不会看到这些数据,但这将有助于开发人员查看布局中是否有可用的视图。事实上,它们可以调整边距、填充和所有其他布局设计时的操作!

最新更新