android - 工具 :listitem for custom view extending RecyclerView

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

我尝试使用 tools:listitemRecyclerView 上显示正确样式的样本数据。这在使用原始 View 时效果很好。

但是当扩展 RecyclerView 以创建我自己的自定义 View 以添加一些功能时,它只会在 Android Studio 的布局预览中显示一个空白区域。

如何在扩展 View 时使用 View 的所有布局预览内容?

我的 View 如下所示:

class TestRecyclerView(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int
) : RecyclerView(context, attrs, defStyle) { }

有什么想法吗?

最佳答案

<com.test.my.TestRecyclerView
        android:id="@+id/your_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:listitem="@layout/your_item"/>

不要忘记在您的自定义 RecyclerView 中添加一个 app:layoutManager 属性!

app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"

enter image description here

关于android - 工具 :listitem for custom view extending RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204830/

相关文章:

android - 每当设备旋转时,使用 libgdx 的应用程序都会重新启动

android - 应用程序在模拟器上运行良好,但在设备上崩溃并出现 : java. lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__aeabi_memcpy"

java - Android 将 ImageView 拖放到另一个 ImageView(或布局)中

java.lang.NoClassDefFoundError : org. jsoup.Jsoup

android - build.phonegap "plugin unsupported: cordova-plugin-device"

android - 错误 : execution failed for task '.app:buildInfoDebugLoader'

java - 安卓工作室 : "Could not get unknown property ' VERSION_NAME' for project of type org. gradle.api.Project"

java - 膨胀类 android.support.v7.widget.CardView 时出错

android - 设置提示时 EditText 不扩展

Android libgdx - 检查是否触摸图像