网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事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());
}
}
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
15739417204)]
[外链图片转存中…(img-5ieRWYeK-1715739417204)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!