为图像添加圆角

路易莎·谢诺斯

如何在图像上添加圆角和阴影,使其看起来像附件一样?

这就是我的活动

        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <!-- Content here -->

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="107dp"
            android:layout_height="166dp"
            android:layout_marginStart="20dp"
            android:elevation="5dp"
            android:scaleType="fitCenter"
            android:translationZ="12dp"
            android:layout_marginTop="15dp" />

在此处输入图片说明

加布里埃尔·马里奥蒂(Gabriele Mariotti)

您有不同的选择。

  • 您可以使用CardView根目录布局。
  • 您可以申请圆角您来LinearLayout使用MaterialShapeDrawable检查这个答案
  • 开始的版本1.2.0-alpha03中的的材料构件库,您可以更改ImageView为新的ShapeableImageView

就像是:

  <com.google.android.material.imageview.ShapeableImageView
      ...
      app:shapeAppearanceOverlay="@style/roundedImageView"
      app:srcCompat="@drawable/ic_custom_image" />

与:

  <style name="roundedImageView" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">8dp</item>
  </style>

或以编程方式:

float radius = getResources().getDimension(R.dimen.corner_radius);
imageView.setShapeAppearanceModel(imageView.getShapeAppearanceModel()
    .toBuilder()
    .setAllCorners(CornerFamily.ROUNDED,radius)
    .build());

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章