Imageview不显示圆角 [英] Imageview not showing rounded corners
本文介绍了Imageview不显示圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试这样布局,但我不能让我的图像视图像这样带有圆角。它在Android工作室的布局编辑器中显示得很好,但在真正的设备上,我得到的是平角。我厌倦了使用XML,也厌倦了代码,但都不适合我。请帮助我使我的版面与此示例图像类似。
我的布局文件
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:clickable="true"
android:background="?android:attr/colorBackground"
android:focusable="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/User_CoverPhoto"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<ImageView
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:background="@drawable/round_shape_only"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/User_CoverPhoto"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/User_ProfilePictures"
app:layout_constraintTop_toTopOf="parent"
/>
<ImageView
android:layout_width="230dp"
android:layout_height="match_parent"
android:background="@drawable/round_shape_only"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/User_ProfilePictures"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="#40000000"
android:backgroundTint="#CC000000"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Profile Picture"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/User_ProfilePictures"
app:layout_constraintHorizontal_bias="0.01"
app:layout_constraintStart_toStartOf="@+id/User_ProfilePictures" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="#40000000"
android:backgroundTint="#CC000000"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Cover Photo"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/User_CoverPhoto" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="13dp"
android:id="@+id/Grid_Recycler">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
圆形的XML
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#CCCCCC"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:radius="15dp"/>
</shape>
推荐答案
只需使用材料组件库中的ShapeableImageView
。
类似于:
<com.google.android.material.imageview.ShapeableImageView
...
app:shapeAppearanceOverlay="@style/roundedCornersImageView"
app:srcCompat="@drawable/ic_image" />
使用:
<style name="roundedCornersImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">xxdp</item>
</style>
*注意:至少需要1.2.0-alpha03
版本。
这篇关于Imageview不显示圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文