Android RecyclerView - 布局预览 - 如何删除复选框附近的“Item 0, Item 1,...”文本?

Lau*_*van 8 android preview android-studio android-recyclerview

我有一个RecyclerView,其中每个列表行项目都有一个CheckBox. 在单独的列表行的布局预览中,Checkbox 显示正确,没有文本:

列表行布局预览 - 屏幕截图

但是,当我查看布局预览作为RecyclerView(使用tools:listitem = "@layout/application_list_content")的一部分时,我看到不需要的示例文本,如“项目 0”、“项目 1”、“项目 3”等:

RecyclerView 布局预览 - 截图

问题:有没有办法让 Android Studio 的布局预览不显示示例文本 - “Item X” - 而只是显示一个空字符串?

的代码RecyclerView是:

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/application_list"
    android:name="com.laurivan.android.ApplicationListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginEnd="?listPreferredItemPaddingRight"
    android:layout_marginStart="?listPreferredItemPaddingLeft"
    app:layoutManager="LinearLayoutManager"
    tools:context="com.laurivan.android.ApplicationListActivity"
    tools:listitem="@layout/application_list_content"/>
Run Code Online (Sandbox Code Playgroud)

项目行有这样的内容:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/list_item_height_normal"
                android:orientation="horizontal"
    >

    <CheckBox
        android:id="@+id/app_checkBox"
        style="?android:attr/starStyle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:layout_margin="0dp"
        android:checked="false"
        android:padding="0dp"
        tools:text=""
        />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

小智 5

如果这对其他人有帮助,我会使用零宽度空白字符来执行此操作,即tools:text="&#8203;"在复选框的布局中:

<CheckBox
    android:id="@+id/app_checkBox"
    style="?android:attr/starStyle"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_margin="0dp"
    android:checked="false"
    android:padding="0dp"
    tools:text="&#8203;"
    />
Run Code Online (Sandbox Code Playgroud)

更多信息:https : //en.wikipedia.org/wiki/Zero-width_space

  • 好答案。您还可以使用空格字符:`tools:text=" "`,它也适用于`RadioButton`。这里有一个类似的错误报告:https://issuetracker.google.com/issues/63651166,但这不是同一个问题。 (2认同)