根据cardview设计制作imageview

make imageview accroding to cardview design

我有一个带圆角的 CardView,我想要一个类似 cardview 的 ImageView,但它不起作用。

我在另一个项目中实现了这段代码,它运行良好,但在我的项目中不起作用

请检查我的代码我没有找到任何解决方案请帮助我。

我的XML文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rlimg"
    android:orientation="vertical"
    android:layout_width="@dimen/_150sdp"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="@dimen/_150sdp"
        android:layout_height="wrap_content"
        app:cardElevation="@dimen/_3sdp"
        android:elevation="@dimen/_12sdp"
        android:layout_centerHorizontal="true"
        app:cardUseCompatPadding="true"
        app:cardPreventCornerOverlap="false"
        android:innerRadius="0dp"
        android:radius="0dp"
        app:cardCornerRadius="@dimen/_10sdp"
        android:shape="ring"
        android:thicknessRatio="1.9">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:id="@+id/imgperformarbg"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_100sdp"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/publiek" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="@dimen/_100sdp"
                android:layout_gravity="bottom"
                android:scaleType="fitXY"
                android:src="@drawable/gradient"/>
        </RelativeLayout>

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/card_view"
        android:layout_marginLeft="@dimen/_4sdp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name"
            android:layout_marginBottom="@dimen/_5sdp"
            android:textColor="#E6000000"
            android:lineSpacingMultiplier=".9"
            android:minLines="1"
            android:maxLines="2"
            android:textSize="@dimen/_12sdp"
            android:id="@+id/txtperformarname"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Detail"
            android:layout_marginBottom="@dimen/_5sdp"
            android:textColor="#CC000000"
            android:textSize="@dimen/_10sdp"
            android:layout_below="@+id/txtperformarname"
            android:visibility="visible"
            android:id="@+id/txtdetails"/>
    </LinearLayout>
</RelativeLayout>

Gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.jenya.tix_tm"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 7
        versionName "1.0.6"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    //sdp
    implementation 'com.intuit.sdp:sdp-android:1.0.5'
    //BottomNavigationViewEx library
    implementation 'com.github.ittianyu:BottomNavigationViewEx:1.1.9'
    //glide
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    //cardview
    implementation 'com.android.support:cardview-v7:27.1.1'
    //volley
    implementation 'com.android.volley:volley:1.1.0'
    //recyclerview multi
    implementation 'com.github.takusemba:multisnaprecyclerview:1.3.3'
    //slider indecator
    implementation 'me.relex:circleindicator:1.2.2@aar'
    //font
    implementation 'com.elmargomez.typer:typerlib:1.0.0'
    //fab_loading
    implementation 'io.saeid:fab-loading:1.0.0'
    //loading_dots
    implementation 'com.github.bhargavms:DotLoader:1.1.1'
}

但是,material 设计指南规定卡片应该有圆角而不是方角。

请帮助我,我是新来的

非常感谢任何帮助。

你提到卡片查看库

com.android.support:cardview-v7:27.1.1

please use this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rlimg"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_centerHorizontal="true"
        app:cardUseCompatPadding="true"
        app:cardPreventCornerOverlap="false"
        android:innerRadius="0dp"
        android:radius="0dp"

        android:shape="ring"
        android:thicknessRatio="1.9">

        <RelativeLayout

            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:id="@+id/imgperformarbg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/h" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:scaleType="fitXY"
                android:src="@drawable/h"/>

        </RelativeLayout
            >

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/card_view"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name"
            android:textColor="#E6000000"
            android:lineSpacingMultiplier=".9"
            android:minLines="1"
            android:maxLines="2"
            android:id="@+id/txtperformarname"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Detail"

            android:textColor="#CC000000"

            android:layout_below="@+id/txtperformarname"
            android:visibility="visible"
            android:id="@+id/txtdetails"
            />
    </LinearLayout>



</RelativeLayout>

问题不在于布局或 Glide。几周前我添加了这个:

android:硬件加速="false" android:largeHeap="true"

由于内存管理问题(我的应用程序将在 Geneymotion 中停止响应)到我的清单。事实证明,它制造的问题比解决问题还多。