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

标签 android android-studio android-recyclerview preview

我有一个 RecyclerView,其中每个列表行项目都有一个 CheckBox。在列表行的布局预览中,复选框正确显示,没有文本:

List row layout preview - screenshot

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

RecyclerView layout preview - screenshot

问题:有没有办法让 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"/>

项目行有这样的东西:

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

最佳答案

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

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

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

关于Android RecyclerView - 布局预览 - 如何删除复选框附近的 "Item 0, Item 1,... "文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36015982/

相关文章:

java - 从 AsyncTask 调用 setAdapter() 时出现 ViewRoot$CalledFromWrongThreadException?

android - 从 RecyclerView 项目到其他 Activity 的值

android - 在单独的 Java 模块中使用 Android 项目文件?

php - RecyclerView 无限滚动与 Volley

android - 更改 View 在 recyclerview 的所有项目中的可见性

android - Google SignIn - Android - 点击时屏幕卡住

android - android中paypal api的问题

android - 如何将 gridview 的高度设置为 wrap_content 到 recyclerview?

android - 自定义键盘 - 无法识别启动 Activity : Default Activity not found

android-studio - 在 Android Studio 中添加 '--warning-mode all' 命令行参数