【问题标题】:Android: support features don't appear in android LAndroid:支持功能不会出现在 android L
【发布时间】:2016-05-15 08:14:07
【问题描述】:

我使用 Android Studio 2.0 。我使用了 RecyclerView 和 CardView,它们 在 kitkat 上正确渲染,但是当应用程序在 SAMSUNG A5 和 android 5.1.1 (lollipop) 上运行时,RecyclerView 不会滚动并且我的 CardView 没有高度和角落。
我尝试了 SO 中建议的解决方案,例如添加
card_view:cardUseCompatPadding="true" 和添加边距。
竟然改了
xmlns:card_view="http://schemas.android.com/apk/res-auto"

xmlns:card_view="http://schemas.android.com/tools"
但是这些都不起作用

这是我的 RecyclerView:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/grid_cards_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:layoutDirection="rtl"
    android:padding="2dp"
    android:background="#e0e0e0"

    />

RecyclerView GridRecyclerView = (RecyclerView) getActivity().findViewById(R.id.grid_cards_recyclerview);
        GridLayoutManager gll = new GridLayoutManager(getActivity(), 2);

        GridRecyclerView.setLayoutManager(gll);
        GridAdapter gridAdapter = new GridAdapter(getActivity(), mylist);
        GridRecyclerView.setAdapter(gridAdapter);

这是一种奇怪的行为:如果我在屏幕上向上移动手指(向下滚动),recyclerview 不会显示任何变化,但如果我去另一个活动并返回,我会看到 recyclerview 已向下滚动!你如何解释这种行为?! Recyclerview 识别滚动动作,但不显示它的反应,也不更新它的视图!

【问题讨论】:

  • 我认为问题可能是因为recyclerview覆盖了整个布局。将 recyclerview 放在一个线性布局/相对布局中。我认为 recyclerview 可能与 match_parent 高度宽度混淆。尝试使其 wrap_content 或在 dp 中提供一些值
  • 我将 height="wrap_content" 的 recyclerView 放在 height="match_parent" 的线性布局中,但不能再工作了。

标签: android scroll android-recyclerview android-cardview android-5.1.1-lollipop


【解决方案1】:

确保您使用的是 com.android.support:recyclerview-v7:22.2.0

(对于 22.2.0 之前的版本,它也不适用于我)

【讨论】:

  • 我使用 com.android.support:recyclerview-v7:23.2.1.
【解决方案2】:

我解决了 RecyclerView 问题。 I searched a lot。我将我的代码写在一个片段中并用于预览它们

fragmentTransaction.add(R.id.fragment_main,
                fragment);

所以在棒棒糖中,我的片段落后于前一个片段并且没有处理触摸所以现在我使用

fragmentTransaction.replace(R.id.fragment_main,
                    fragment);

现在recyclerView 正在滚动。

对于阴影,我使用了card_view:cardUseCompatPadding="true",但由于我在 Manifest 中将 android:hardwareAccelerated 设置为 false,因此无法正常工作。让它成真解决了问题。

【讨论】:

    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    相关资源
    最近更新 更多