当前位置: 首页 > 知识库问答 >
问题:

在静态编程语言RecyclerView项目不显示

鱼征
2023-03-14

我是一个初学静态编程语言的学生,正在学习一个html" target="_blank">示例回收人员视图。我开始编码,但没有得到我应该得到的结果,即使在检查和重新检查代码之后也是如此。然后我注意到,即使使用非常基本的代码,它仍然没有按照应有的方式运行。我将包含基本代码,当使用tools: listitem时,它应该显示一个通用列表。我只得到列表中的一项。我怀疑代码以外的其他东西正在影响结果;但是我还没有达到知道的水平。

请看活动内容。xml:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@layout/recyclerview_item"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:id="@+id/recycler_view"/>

</androidx.constraintlayout.widget.ConstraintLayout>

注意它有tools:listitem行。

下面是列表(recyclerview\u item.xml):

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/titleTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:text="Title"/>

    <TextView
        android:id="@+id/timeTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="12:42"/>

    <View
        android:layout_width="wrap_content"
        android:layout_height="1dp"
        android:background="#C3C3C3"/>

</LinearLayout>

起初,它是一种约束性的户外活动,但我在某处读到,线性户外活动可以治愈这种疾病。

然后是活动。kt是启动项目的标准。不折不扣:

package com.example.recyclerexample2
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

这是一个捕获,显示了仅显示1个项目的xml文件的设计,而不是完全填充项目。

这是在xml文件中添加listitem行之前。

我正在使用:Android Studio Arctic Fox | 2020.3.1补丁4 Build#AI-203.7717.56.2031.7935034,于2021 11月21日构建运行时版本:11.0.10 0-b96-7249189 amd64 VM:OpenJDK 64位服务器VM由Oracle Corporation Windows 10 10.0 GC:G1 Young Generation,G1 Old Generation内存:1280M内核:12注册表:外部。系统汽车进口disabled=真正的非捆绑插件:com。intellij。市场,com。思想工作。测量

任何帮助都将不胜感激。

射线

共有1个答案

洪开诚
2023-03-14

您应该为您的列表项使用“wrap_content”

 类似资料:
  • 我正在尝试为我的Kotlin RecyclerView实现一个onClickListener。它根本没有开火。代码没有标记为红色或类似的东西。你在NotesActivity中看到的日志和吐司。我们没有被处决。我的recyclerview本身就在工作,但onClickListener根本不会启动。 NotesAdapter。kt NotesActivity。kt adapter_note_layou

  • 正如标题所说,我正在尝试将Java和Kotlin混合在一个项目中。这里有一个很好的例子。混合java kotlin hello world。除了kotlin在src/main/Java/somepackage/SomeClass中找不到我的任何Java类之外,所有的东西都正常工作。Java语言 这是什么原因? 我的身材。gradle看起来像这样 而不是开始尝试在更大的项目上实现这一点。我试图通过创

  • 我试图使用Reform2显示来自虚拟服务器(JSON服务器)的JSON数据,并将其显示在片段中的RecyclerView中。到目前为止,正在发生以下事件(使用日志信息发现): 主片段<代码>字符片段(CharactersListFragment)。kt创建已启动 只调用了。它正在返回0 未调用OnCreateViewHolder()和onBindViewHolder() 成功地从服务器获取数据并将

  • 我试图用OkHttp和Cucumber在静态编程语言中设置一个Spring启动项目,并且在运行Cucumber任务时遇到以下错误。如何修复? 还有build gradle kts片段 我看到了这个错误https://github.com/square/okio/issues/647看起来可能是它,并修复了这个build.gradle,我如何将其翻译为kotlinbuild.gradle.kts?

  • 如图所示,https://stackoverflow.com/a/16639438/8949356,在Java中,当声明的类是公共类时,可以重写其函数 但是我想知道如何用静态编程语言编写完全相同的代码,我已经尝试了很多,但没有找到任何关于这个主题的东西。我可以在Java中去做这件事,但我的其余代码是用静态编程语言编写的,而且我不能一直带着这种怀疑;静态编程语言对我来说是一个很好的工具,我想学习它。

  • 需要帮助。我已经检查了堆栈溢出中的其他一些解决方案,但我没有到达使我的片段工作。 问题:当我显示我的片段时,我的屏幕是空的,我有错误“E/RecyclerView:没有连接适配器;跳过布局” 3个问题(当然有联系): E/RecyclerView:未连接适配器;跳过布局错误 片段(XML) 一行数据(一天) 片段类 适配器类 我尝试在onCreateView、onCreate和onResume中初