java - CardView 无法正常工作

标签 java android android-recyclerview android-6.0-marshmallow cardview

我有一个 RecyclerView 的工作,我也使用 CardView。我已经制定了所有这些标准程序(创建了 ViewHolder,实现了必要的方法)但问题是 CardView 的角不是圆的。我只得到CardView 的矩形角。

这里是 Adapter 的“主布局”的 XML 代码:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_margin="15dp"
    card_view:cardElevation="10dp"
    card_view:cardCornerRadius="30dp">

    <RelativeLayout
        android:layout_margin="20dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/adapterText"
            android:text="@string/textCaption"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/adapterDate"
            android:text="@string/date"
            android:layout_marginTop="10dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/adapterText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</android.support.v7.widget.CardView>

还有另一个带有 RecyclerView 的布局:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="10dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

</RelativeLayout>

以及 RecyclerView 的初始化:

@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
    if (root != null) {
        RecyclerView mRecyclerContactList=(RecyclerView)(root.findViewById(R.id.contactList));
        mContactAdapter=new ContactAdapter(getContext(),mContextualMultiMode,mContactList);
        mRecyclerContactList.setAdapter(mContactAdapter);
        RecyclerView.ItemAnimator animator=new DefaultItemAnimator();
        mRecycle

rContactList.setItemAnimator(animator);
            RecyclerView.ItemDecoration mVerticalDecoration=new DividerItemDecoration
                    (getContext(), LinearLayoutManager.VERTICAL);
            mRecyclerContactList.addItemDecoration(mVerticalDecoration);
            mRecyclerContactList.setLayoutManager(new LinearLayoutManager(getContext()));

        }

    }

有人知道如何解决这个问题吗?

最佳答案

作为 root 的 Cardview 给我带来了奇怪的问题。尝试以根用户身份使用 Relativelayout。

关于java - CardView 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39606243/

相关文章:

android 谷歌地图 mapview 按钮错误

java - 具有不同类型元素的复杂 ArrayList

java - 观察者与注册回调

java - Android 错误

java - Chartboost Android 集成 - 如何监听加载的广告

android - Firefox for Android native 应用程序图标(地址栏)

android - RecyclerView 比 Android 中的 viewPager 好吗?

android - Recyclerview 仅显示光标中的前五个项目

android - 如何更改 recyclerview 第一行布局?

java - 结合两种方法。 int 不能取消引用