Google官方控件ShapeableImageView使用

定制气泡效果:ShapeableImageView的多样圆角与裁切应用
本文详细展示了如何使用ShapeableImageView在Android中实现自定义的气泡效果,包括圆形、切角和不同区域的混合圆角,以及带有边框的图片样式。通过XML布局和样式文件,展示了如何调整图片尺寸、圆角大小和形状特性。

上面都是用ShapeableImageView写出来的效果

直接上代码:

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    tools:context=".MainActivity">


    <com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/image0"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="20dp"
        android:src="@mipmap/image"
        app:layout_constraintEnd_toStartOf="@id/image1"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/image1"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="20dp"
        android:src="@mipmap/image"
        app:layout_constraintEnd_toStartOf="@id/image2"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toEndOf="@id/image0"
        app:layout_constraintTop_toTopOf="parent"
        app:shapeAppearance="@style/RoundedStyle1" />

    <com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/image2"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="20dp"
        android:src="@mipmap/image"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintStart_toEndOf="@id/image1"
        app:layout_constraintTop_toTopOf="parent"
        app:shapeAppearance="@style/RoundedStyle2" />

    <com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/image3"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="20dp"
        android:padding="2dp"
        android:src="@mipmap/image"
        app:layout_constraintEnd_toStartOf="@id/image4"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值