2024年最新Google发布,玩转ShapeableImageView,告别第三方库,2024年最新腾讯&字节&爱奇艺&网易&华为实习面试汇总

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

android:padding=“1dp”
android:src=“@drawable/head”
/>

跟ImageView效果一样。

####各种花俏样式 1、圆角图片

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image1”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/roundedCornerStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

2、圆形图片

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image2”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/circleStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

3、切角图片

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image3”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/cutCornerStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

4、菱形图片

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image4”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/diamondStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

5、右上角圆角图片

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image5”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/topRightCornerStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

6、小鸡蛋图片

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image6”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/eggStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

7、组合弧度图片效果

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image7”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/comCornerStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

8、 小 Tips

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image8”
android:layout_width=“110dp”
android:layout_height=“50dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/tipsCornerStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

9、扇形图片

<com.google.android.material.imageview.ShapeableImageView
android:id=“@+id/image9”
android:layout_width=“110dp”
android:layout_height=“110dp”
android:padding=“1dp”
android:src=“@drawable/head”
app:shapeAppearance=“@style/fanStyle”
app:strokeColor=“@android:color/holo_blue_bright”
app:strokeWidth=“2dp”/>

对应的style:

通过源码学知识

从前面应用可以发现,通过定义ShapeableImageView的shapeAppearance属性style值,可以实现各种不同的样式,而style有哪些的属性,分别表示什么,定义了这些style实现这些样式效果的原理是什么,带着这些疑问阅读源码。

public ShapeableImageView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(wrap(context, attrs, defStyle, DEF_STYLE_RES), attrs, defStyle);
// Ensure we are using the correctly themed context rather than the context that was passed in.
context = getContext();

clearPaint = new Paint();
clearPaint.setAntiAlias(true);
clearPaint.setColor(Color.WHITE);
clearPaint.setXfermode(new PorterDuffXfermode(Mode.DST_OUT));
destination = new RectF();
maskRect = new RectF();
maskPath = new Path();
TypedArray attributes =
context.obtainStyledAttributes(
attrs, R.styleable.ShapeableImageView, defStyle, DEF_STYLE_RES);

strokeColor =
MaterialResources.getColorStateList(
context, attributes, R.styleable.ShapeableImageView_strokeColor);

strokeWidth = attributes.getDimensionPixelSize(R.styleable.ShapeableImageView_strokeWidth, 0);

borderPaint = new Paint();
borderPaint.setStyle(Style.STROKE);
borderPaint.setAntiAlias(true);
shapeAppearanceModel =
ShapeAppearanceModel.builder(context, attrs, defStyle, DEF_STYLE_RES).build();
shadowDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
setOutlineProvider(new OutlineProvider());
}
}

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

15739417204)]
[外链图片转存中…(img-5ieRWYeK-1715739417204)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值