【问题标题】:image in cardview with top radius not showing corner radius顶部半径不显示角半径的cardview中的图像
【发布时间】:2023-04-01 20:02:01
【问题描述】:

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

我试过这些问题:questionquestion。但是问题还是一样。

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>

我的输出图像: https://imgur.com/a/FequXmj

【问题讨论】:

标签: java android cardview radius


【解决方案1】:

试试这个..

<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>

看起来像这样...结果

【讨论】:

  • 不起作用并且您使用的图像没有占用cardview的完整宽度使用一个占用cardview完整宽度的图像然后看到它不会占用cardview的角半径@Faiz Mir
  • 给我发一张你正在使用的图片 faizmir53@gmail.com
猜你喜欢
  • 2015-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-17
  • 2023-04-03
  • 2020-10-06
  • 2018-12-28
  • 1970-01-01
相关资源
最近更新 更多