ImageView 在 cardView 中不匹配 - Android
ImageView don't match in cardView - Android
我有波纹管 xml :
<RelativeLayout
android:id="@+id/relative_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/relative_two"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_product_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
<TextView
android:id="@+id/status_product_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:visibility="invisible" />
</RelativeLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/relative_three"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="@+id/relative_two">
<Spinner
android:id="@+id/select_spinner"
android:layout_width="15dp"
android:layout_height="0dp"
android:layout_marginRight="5dp"
android:dropDownVerticalOffset="40dp"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/name_product_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:ellipsize="marquee"
android:gravity="right"
android:maxLines="1"
android:text="TEXT"
app:layout_constraintRight_toLeftOf="@+id/select_spinner"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/count_products_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="TEXT"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/select_spinner"
app:layout_constraintTop_toBottomOf="@+id/name_product_textview" />
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
在上面 xml
我有波纹管 ImageView
:
<ImageView
android:id="@+id/image_product_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
问题:我的ImageView
不match
在cardView
(左右和上)。它有2或3 space 周围 ImageView
(左右和顶部)。
在我的源代码中,我将图像设置为如下所示:
Picasso.with(context)
.load(productsModelList.getPictureUrl())
.placeholder(AppCompatDrawableManager.get().getDrawable(context, R.drawable.placeholder_pictures))
.fit()
.into(image_product_imageview);
这 space 是 CardView
支持早于 L (API 20) 的系统的结果。为了使您的布局在 pre-Lollipop(和 pre-CardView
小部件)或 Lollipop 和较新的 上看起来相同,Android引入了一些额外的属性。
因为重叠(圆角)内容对于旧的Android版本来说很难,所以cardPreventCornerOverlap
已经添加并默认设置作为 true
。这就是为什么你的 ImageView
周围有白色条纹 - 你可以自己检查它们的宽度是否与 cardCornerRadius
值密切相关。
要删除此填充关闭 cardPreventCornerOverlap。你可以做到:
通过 xml 通过 card_view:cardPreventCornerOverlap="false"
或以编程方式 由 yourCardView.setPreventCornerOverlap(false)
.
请记住,这只为 API 20+ 提供了您想要的效果。
在具有旧版本系统的设备上,您的圆角将不可见(隐藏在非圆角图像下)。
要了解更多信息,请查看 the CardView doc。在第一段中,您可以找到关于您的问题的官方说明。
我有波纹管 xml :
<RelativeLayout
android:id="@+id/relative_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/relative_two"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_product_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
<TextView
android:id="@+id/status_product_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:visibility="invisible" />
</RelativeLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/relative_three"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="@+id/relative_two">
<Spinner
android:id="@+id/select_spinner"
android:layout_width="15dp"
android:layout_height="0dp"
android:layout_marginRight="5dp"
android:dropDownVerticalOffset="40dp"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/name_product_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:ellipsize="marquee"
android:gravity="right"
android:maxLines="1"
android:text="TEXT"
app:layout_constraintRight_toLeftOf="@+id/select_spinner"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/count_products_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="TEXT"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/select_spinner"
app:layout_constraintTop_toBottomOf="@+id/name_product_textview" />
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
在上面 xml
我有波纹管 ImageView
:
<ImageView
android:id="@+id/image_product_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
问题:我的ImageView
不match
在cardView
(左右和上)。它有2或3 space 周围 ImageView
(左右和顶部)。
在我的源代码中,我将图像设置为如下所示:
Picasso.with(context)
.load(productsModelList.getPictureUrl())
.placeholder(AppCompatDrawableManager.get().getDrawable(context, R.drawable.placeholder_pictures))
.fit()
.into(image_product_imageview);
这 space 是 CardView
支持早于 L (API 20) 的系统的结果。为了使您的布局在 pre-Lollipop(和 pre-CardView
小部件)或 Lollipop 和较新的 上看起来相同,Android引入了一些额外的属性。
因为重叠(圆角)内容对于旧的Android版本来说很难,所以cardPreventCornerOverlap
已经添加并默认设置作为 true
。这就是为什么你的 ImageView
周围有白色条纹 - 你可以自己检查它们的宽度是否与 cardCornerRadius
值密切相关。
要删除此填充关闭 cardPreventCornerOverlap。你可以做到:
通过 xml 通过
card_view:cardPreventCornerOverlap="false"
或以编程方式 由
yourCardView.setPreventCornerOverlap(false)
.
请记住,这只为 API 20+ 提供了您想要的效果。 在具有旧版本系统的设备上,您的圆角将不可见(隐藏在非圆角图像下)。
要了解更多信息,请查看 the CardView doc。在第一段中,您可以找到关于您的问题的官方说明。