Android: support features don't appear in android L

妖精的绣舞 提交于 2019-12-07 21:44:25

问题


I use Android Studio 2.0 . I have used RecyclerView and CardView which render properly on kitkat but when the app is run on SAMSUNG A5 with android 5.1.1 (lollipop) the RecyclerView doesn't scroll and my CardView doesn't have elevation and corner.
I tried solutions suggested in SO such as adding
card_view:cardUseCompatPadding="true" and adding margin.
Even changed
xmlns:card_view="http://schemas.android.com/apk/res-auto"
to
xmlns:card_view="http://schemas.android.com/tools"
But these didn't work

This is my 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);

this is a strange behavior: if I move up my finger on screen (scroll down), recyclerview doesn't show any change but if I go to another activity and come back I see the recyclerview has scrolled down!! How do you explain this behavior?! Recyclerview recognizes scroll motion but doesn't show its reaction and doesn't update its view!


回答1:


Make sure you're using com.android.support:recyclerview-v7:22.2.0

(With version prior to 22.2.0 it didn't work for me either)




回答2:


I solved RecyclerView issue. I searched a lot. I write my code in a fragment and for previewing them I used

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

so in lollipop my fragment went behind the previous fragment and didn't handle touches so now I use

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

Now recyclerView is scrolling.

For shadow I used card_view:cardUseCompatPadding="true" but didn't work because I set android:hardwareAccelerated in Manifest to false. Making it true solved the problem.



来源:https://stackoverflow.com/questions/37235950/android-support-features-dont-appear-in-android-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!