java - 卡片 View 中的图像,顶部半径不显示角半径

标签 java android cardview radius

我有recyclerView,它位于具有ImageView的cardView内部,并且占据了其高度的70%。所以我给了cardView 的角半径。显示了cardView半径的底部,但问题是被图像覆盖的顶部部分没有采用cardView的角半径。

我尝试了这些问题:question , question 。但问题还是一样。

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:id="@+id/card_view"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/_200sdp"
    android:layout_marginRight="@dimen/_15sdp"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="15dp"
    card_view:cardCornerRadius="@dimen/_20sdp"
    card_view:cardBackgroundColor="@color/White"
    android:layout_marginBottom="@dimen/_10sdp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/party_image"
            android:layout_width="@dimen/_160sdp"
            android:layout_height="@dimen/_140sdp"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/party_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            android:text="John Doe"
            android:textColor="@color/colorPrimary"
            android:gravity="center"
            android:paddingBottom="8dp"
            android:paddingTop="8dp"
            />

    </LinearLayout>

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

我的输出图像: /image/9kZi6.jpg

最佳答案

试试这个..

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"

    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_gravity="center"

    android:layout_margin="8dp"
    android:background="@drawable/shape"

    android:elevation="4dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:elevation="4dp"
        app:cardCornerRadius="8dp">

        <ImageView
            android:id="@+id/thumbnaill"
            android:layout_width="160dp"
            android:layout_height="140dp"
            android:layout_gravity="left"
            android:background="@drawable/sa"
            android:scaleType="fitXY"
            />
    </android.support.v7.widget.CardView>
</FrameLayout>

在你的Drawable中创建一个xml shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <!-- you can use any color you want I used here gray color-->
    <solid android:color="#ffffff"/>
    <corners android:radius="8dp"/>
    <!--<stroke android:width="0.5dp" android:color="@color/darker_gray"/>-->
</shape>

它看起来像这样......结果

enter image description here

关于java - 卡片 View 中的图像,顶部半径不显示角半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50364978/

相关文章:

java - 如何将负整数值转换为 char 数据类型

Android 不会滚动 https iframe

android-studio - Android Studio : Component is selected but Attributes editor says "No component selected"

android - 自定义您的 ImageCardView 样式(不是内容)

java - LocaleChangeInterceptor.preHandle 中的对象处理程序有什么用

java - JAX-RS异常: Annotated with GET of resource,类未被识别为有效的资源方法

iphone - 手机 : google maps api or native sdk - capabilities?

android - 从一侧移除 CardView 阴影

java - 打开新舞台窗口时的应用程序 "freeze"

java - 如何正确运行后台服务?