只有一个圆角的ImageView [英] ImageView with only one rounded corner

本文介绍了只有一个圆角的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使 ImageView 的一个圆角如下图所示,但右下角。尝试使用背景形状,但完全无法使用。 Glide加载的所有图像。我应该使用 ViewOutlineProvider 之类的东西吗?有有效的方法可以做到这一点吗?谢谢!

 < shape xmlns:android = http://schemas.android.com/apk/res/android > 
< corners
android:radius = 2dp
android:bottomRightRadius = 20dp
android:bottomLeftRadius = 0dp
android:topLeftRadius = 0dp
android:topRightRadius = 0dp />
< / shape>

解决方案


I'm trying to make one rounded corner of ImageView like in the picture below but with bottom right corner. Tried using background shape but it's not working at all. All images loaded by Glide. Should i use something like ViewOutlineProvider? Is there are an efficient way to do this? Thanks!

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners
        android:radius="2dp"
        android:bottomRightRadius="20dp"
        android:bottomLeftRadius="0dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp"/>
</shape>

解决方案

The Material Components library provides a shape library that can be used to create shapes using the MaterialShapeDrawable.

The version 1.2.0-alpha03 introduced the ShapeableImageView.
Just use something like:

  <com.google.android.material.imageview.ShapeableImageView
      android:id="@+id/image_view"
      android:scaleType="centerInside"
      android:adjustViewBounds="true"
      ../>

and in your code you can apply the ShapeAppearanceModel with:

ShapeableImageView imageView = findViewById(R.id.image_view);
float radius = getResources().getDimension(R.dimen.default_corner_radius);
imageView.setShapeAppearanceModel(imageView.getShapeAppearanceModel()
    .toBuilder()
    .setTopRightCorner(CornerFamily.ROUNDED,radius)
    .build());

这篇关于只有一个圆角的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆