【问题标题】:Use of layout tools attribute布局工具属性的使用
【发布时间】:2018-05-16 04:27:37
【问题描述】:

布局工具属性在 Android Studio 3.1.2 中不起作用是否有任何可能的原因?它确实显示了工具,但找不到列表项、文本等!

    <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"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:text="Test Text"

        >
    </android.support.v7.widget.RecyclerView>

</FrameLayout>

请参阅here 了解错误。

【问题讨论】:

  • 您可能已经这样做了,Gradle 同步有时可能会起作用?
  • 请详细说明
  • tools:text, tools:listitem etc 给了我错误并且没有出现在基本代码完成中(ctrl + space)

标签: android android-layout android-studio layout android-recyclerview


【解决方案1】:

RecyclerView 元素中的属性tools:text 应该是固定的。

<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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@android:layout/simple_list_item_checked"
        tools:itemCount="3" />

</FrameLayout>

【讨论】:

  • 抱歉,格式化时出错。你是什​​么意思工具:文本损坏我是参考this学习。
  • 是的,坏掉了......说没有'='符号后跟一个(蓝色)带引号的字符串值,在以'tools:text'开头的行中
  • 根据this,你可以用tools:itemCount换成RecyclerView
  • 您可以将tools:text 用于TextView
  • @Dave 是的,="..." 不见了。
猜你喜欢
  • 2021-11-12
  • 2018-06-20
  • 2021-06-27
  • 2012-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多