gpt4 book ai didi

java - Android RecyclerView 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:00:53 32 4
gpt4 key购买 nike

今天我尝试使用新的 android RecyclerView。我创建了一个包含空白 Activity 的新项目,并将以下内容添加到其布局中:

<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

在 gradle 构建依赖项中,我添加了:

compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.android.support:cardview-v7:21.+'

但 activity_main.xml 渲染仍然显示以下错误:

Rendering Problems The following classes could not be instantiated:
- android.support.v7.widget.RecyclerView (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.UnsupportedOperationException: Unsupported Service: accessibility   at com.android.layoutlib.bridge.android.BridgeContext.getSystemService(BridgeContext.java:465

我自己似乎没有在网络上找到解决方案,因为每个人都说“在你的 gradle 构建中实现以下依赖项:......”我已经添加了。

谁能提供解决方案?

问候Tak3r07

编辑:创建时:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

最佳答案

我认为使用 RecyclerView 至少要设置布局管理器。

如果您阅读文档 here :

In contrast to other adapter-backed views such as ListView or GridView, RecyclerView allows client code to provide custom layout arrangements for child views. These arrangements are controlled by the RecyclerView.LayoutManager. A LayoutManager must be provided for RecyclerView to function.

您可以在实例化 RecyclerView 后尝试像这样设置 LayoutManager :

recyclerView.setLayoutManager(new LinearLayoutManager(this));

(稍后将其更改为更符合您需求的 LayoutManager )

关于java - Android RecyclerView 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26830686/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com