动画无法在我的RecyclerView上运行

时间:2015-05-15 04:01:49

标签: android android-layout android-animation android-recyclerview android-cursor

我正在尝试让项目动画在RecyclerView上运行。动画意味着使用标准DefaultItemAnimator,而RecyclerView显示了一整套CardViews。不幸的是,我根本无法获得动画。我的代码包含在下面,但在logcat中没有错误,我很难确定故障的根源。如果需要,请询问更多信息。

在我的片段中,我有:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.fragment_main, container, false);

    mRecyclerView = (RecyclerView)layout.findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);

    mRVLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mRVLayoutManager);

    // the cursor is successfully swapped into the adapter when the loader does it's job
    mCursorAdapter = new RationCursorAdapter( null );
    mRecyclerView.setAdapter(mCursorAdapter);

    /////////
    // this should work right?!
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    /////////

    return layout;
}

RecyclerView按预期显示列表,据我所知,该列表运行平稳且正常,但动画从未显示过。

通过ContentProvider

添加项目
ContentResolver resolver = getContentResolver();
resolver.insert(DataContract.Entry.CONTENT_URI, content_values);

看起来像这样:

@Override
public Uri insert(Uri uri, ContentValues values) {
    if( uriMatcher.match(uri) == ENTRY_URI ){
        SQLiteDatabase DB = dbHelper.getWritableDatabase();
        long id = DB.insert(
            DataContract.Entry.TABLE_NAME,
            null,
            values
        );

        if(id != -1 ){

            // successfully inserted
            getContext().getContentResolver().notifyChange( uri, null );
            return DataContract.Entry.buildEntryUri(id);
        }
        // problem inserting
        throw new SQLException("Error inserting into database with URI " + uri);
    }

    throw new IllegalArgumentException("Inserting is not supported with URI " + uri);
}

我在运行Android 5.1的Nexus手机上运行所有这些

有关如何使这项工作的任何想法? 感谢。

0 个答案:

没有答案