Android 回收视图周围的白色边框
我有一个带有物品的回收视图。当我在棒棒糖设备上运行它时,一切都很棒。但当我在棒棒糖前的设备上运行它时,每个视图周围都有一个白色边框 编辑:我之前没有发布代码,因为我认为这是某种错误 Rec.xmlAndroid 回收视图周围的白色边框,android,image,android-recyclerview,Android,Image,Android Recyclerview,我有一个带有物品的回收视图。当我在棒棒糖设备上运行它时,一切都很棒。但当我在棒棒糖前的设备上运行它时,每个视图周围都有一个白色边框 编辑:我之前没有发布代码,因为我认为这是某种错误 Rec.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_widt
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#333333"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/text"
android:scrollbars="vertical" />
</RelativeLayout>
main_card_view.xml
<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:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#222222"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/image"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<RelativeLayout
android:layout_width="320dp"
android:layout_height="240dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="@+id/image"
android:background="#bb000000"
android:id="@+id/rel_color">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Μπύρα"
android:textColor="#fcfcfc"
android:textSize="40sp"
android:shadowDx="1"
android:shadowDy="1"
android:shadowColor="#000000"
android:id="@+id/text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8$"
android:id="@+id/textView3"
android:textColor="#fcfcfc"
android:layout_alignParentBottom="true"
android:textSize="28sp"
android:shadowDx="1"
android:shadowDy="1"
android:shadowColor="#000000"
android:layout_alignBottom="@+id/text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_margin="10dp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
问题是因为CardView
在您的CardView上设置setPreventCornerOverlap(false)
并扩展ImageView以创建一个类似RoundedCornerImageView的自定义类,并在CardView而不是ImageView中使用它
注意:您可以创建自己的自定义类,即RoundedCornerIm。。。或者在链接的SO问题中使用lib,例如
编辑:
好吧我觉得你有点困惑所以
1) RecyclerView
是列表/网格的容器布局。i、 e
android:id="@+id/my_recycler_view"
正如我在图片中看到的,您必须将GridLayoutManager
附加到RecyclerView
。同样,要将数据放入RecyclerView
中,还必须附加适配器
同样,如果您有一个适配器,即扩展适配器类的类(可能是RecyclerView.adapter
)。现在必须为适配器类提供一个要膨胀的布局,即main\u card\u view.xml
内部RecyclerView
网格样式,因为GridLayoutManager
因此,您的RecyclerView中的每个项目都是一个main_card_view.xml
现在,在扩展适配器类(即连接到回收器视图)的类中,将有CardView
--您必须在那里进行更改。请在此发布一些代码更新我的问题。因此,我必须将RecyclerView添加到CardView,使其看起来相同?没有办法在RecyclerView上这么做?没有!您不必更改回收器视图。回收器视图和卡片视图是不同的。在回收器视图中有一个卡片视图。例如android.support.v7.widget.cardwiew(即在main_card_view.xml中),您必须在main_card_view.xml中进行这两项更改!问我你是否还不跟进对不起,我还是不明白。CardView是有助于查看的布局。我的主要布局是RecyclerView。我可以参考recyclerview,因为它在我的Rec.xml中是我的主要布局。当我的布局中只有一个RecyclerView时,我如何才能参考CardView?谢谢你的回答,你是对的,尽管我不能再这样做了。我使用了另一种方式,我添加了您在XML中所说的内容。card_view:cardPreventCornerOverlap=“false”并且工作正常。看来我还得再试一点我有点糊涂了!再次非常感谢你!很高兴我能帮忙,事实上也是一样。我告诉过您如何在java文件中实现它,您通过更改xml解决了这个问题。你会及时明白的:祝你度过愉快的一天:)