Android ShapeableImageView使用详解,告别shape、三方库

app:strokeWidth=“4dp” />

  • app:strokeColor 描边颜色

  • app:strokeWidth 描边宽度

  • 注意这里padding的数值是描边宽度的一半,后面会说

切角

在这里插入图片描述

<com.google.android.material.imageview.ShapeableImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_margin=“10dp”

android:padding=“2dp”

android:src="@mipmap/ic_avatar"

app:shapeAppearance="@style/CutStyle"

app:strokeColor="@color/red"

app:strokeWidth=“4dp” />

  • cornerFamily:cut 处理模式变为裁剪

菱形

在这里插入图片描述

<com.google.android.material.imageview.ShapeableImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_margin=“10dp”

android:padding=“2dp”

android:src="@mipmap/ic_avatar"

app:shapeAppearance="@style/RhombusStyle"

app:strokeColor="@color/red"

app:strokeWidth=“4dp” />

  • 同样,裁剪模式下圆角大小也可以计算

叶子

在这里插入图片描述

<com.google.android.material.imageview.ShapeableImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_margin=“10dp”

android:padding=“2dp”

android:src="@mipmap/ic_avatar"

app:shapeAppearance="@style/LeafStyle"

app:strokeColor="@color/red"

app:strokeWidth=“4dp” />

  • cornerSizeTopLeft 左上圆角

  • cornerSizeBottomRight 右下圆角

  • 以此类推,左上、左下、右上、右下等

半圆

在这里插入图片描述

<com.google.android.material.imageview.ShapeableImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_margin=“10dp”

android:padding=“2dp”

android:src="@mipmap/ic_avatar"

app:shapeAppearance="@style/SemicircleStyle"

app:strokeColor="@color/red"

app:strokeWidth=“4dp” />

六边形

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CountDownLatch是Java中的一个同步工具类,用于控制多个线程的执行顺序。它通过一个计数器来实现,该计数器初始化为一个正整数,每当一个线程完成了自己的任务后,计数器的值就会减1。当计数器的值减到0时,所有等待的线程就会被唤醒继续执行。 在Android中,CountDownLatch可以用于等待多个异步操作完成后再执行某个任务,或者等待多个线程都达到某个状态后再继续执行。 下面是CountDownLatch的基本使用方法: 1. 创建CountDownLatch对象,并指定计数器的初始值。 ```java CountDownLatch latch = new CountDownLatch(3); // 计数器初始值为3 ``` 2. 在需要等待的地方调用`await()`方法,使当前线程进入等待状态,直到计数器值为0时才会继续执行。 ```java try { latch.await(); // 等待计数器值为0 } catch (InterruptedException e) { e.printStackTrace(); } ``` 3. 在需要通知其他线程继续执行的地方调用`countDown()`方法,将计数器的值减1。 ```java latch.countDown(); // 计数器减1 ``` 下面是一个简单的示例,演示了如何使用CountDownLatch等待多个线程完成后再执行某个任务: ```java import java.util.concurrent.CountDownLatch; public class CountDownLatchExample { public static void main(String[] args) { final CountDownLatch latch = new CountDownLatch(3); for (int i = 0; i < 3; i++) { final int threadNum = i; new Thread(() -> { try { Thread.sleep(1000); System.out.println("Thread " + threadNum + " completed."); latch.countDown(); } catch (InterruptedException e) { e.printStackTrace(); } }).start(); } try { latch.await(); System.out.println("All threads completed. Start executing the task..."); // 执行任务 } catch (InterruptedException e) { e.printStackTrace(); } } } ``` 在上面的示例中,我们创建了一个初始值为3的CountDownLatch对象。然后创建了3个线程,每个线程会在执行完任务后将计数器减1。主线程调用`await()`方法等待计数器的值变为0,当所有线程都执行完任务后,主线程才会继续执行并输出"All threads completed. Start executing the task..."。 希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值