根据卡片视图设计制作图像视图



我有一个圆角的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>

渐变文件

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

然而,材料设计指南指出,卡片应该有圆角,而不是直角。

请帮帮我,我是新来的

如有任何帮助,我们将不胜感激。

您提到的是卡片视图库

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:hardwareAccelerated="false"android:largeHeap="true">

由于内存管理问题(我的应用程序将在Geneymotion中停止响应(,导致我的Manifest。事实证明,它制造的问题比解决的问题更多。

最新更新