我在剪裁约束布局视图时遇到问题。
这是我的xml布局代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/deck_card_corner_radius"
android:clipChildren="true"
>
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scaleType="centerCrop"
app:srcCompat="@drawable/splashscreen" />
</android.support.constraint.ConstraintLayout>
deck_card_corner_radius
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="270" android:endColor="#316db2" android:startColor="#316db2" />
<corners android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp" android:topLeftRadius="30dp" android:topRightRadius="30dp"/>
</shape>
在没有图像的情况下我得到了这个
使用图像
有人能帮我吗?
发布于 2018-07-10 05:52:51
使用CardView怎么样?
我不认为设置圆角背景实际上“塑造”了视图半径。它仍然是一个带有锐利边缘的矩形,只是在其中渲染了圆角的背景。您可以通过查看布局编辑器来查看此内容。如果你点击视图,你知道它实际上不是圆形的,即使在设置了圆角的背景之后。
我一直在使用CardView来做这件事,它工作得很好。
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardPreventCornerOverlap="false"
app:cardCornerRadius="4dp"
app:cardUseCompatPadding="true">
<!-- Content goes here i.e. ImageView, ConstraintLayout, etc... -->
</android.support.v7.widget.CardView>
这里最重要的是app:cardPreventCornerOverlap=false
.它剪辑内容,以便它可以流畅地适合容器视图,而不需要任何不必要的填充。文档是here。
https://stackoverflow.com/questions/51254077
复制相似问题