GenaralRoundLayout,淘汰了80%的Android面试者

文章介绍了如何在Android开发中实现自定义圆角View(GeneralRoundImageView),通过IRoundView接口、attrs文件配置和dispatchDraw方法的重写。作者还强调了自学Android技能时的策略,包括利用GitHub资源学习MaterialDesign控件,以及对NDK和JVM基础知识的理解和实践建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

interface IRoundView {

fun setCornerRadius(cornerRadius: Float)

fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

}

  • 2、定义 attrs 属性

在你的 attrs 的文件中,定义 declare-styleable 属性(为了可以在 xml 文件中输入的时候自动提示)

  • 2、让 GeneralRoundImageView 实现 IRoundView 接口的方法

public class GeneralRoundImageView extends AppCompatImageView implements IRoundView {

public GeneralRoundImageView(Context context) {

this(context, null);

}

public GeneralRoundImageView(Context context, @Nullable AttributeSet attrs) {

super(context, attrs);

}

public GeneralRoundImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

}

@Override

public void setCornerRadius(float cornerRadius) {

}

@Override

public void onLayout(boolean changed, int left, int top, int right, int bottom) {

super.onLayout(changed, left, top, right, bottom);

}

}

  • 3、在 GeneralRoundImageView 中定义 GeneralRoundViewImpl 对象,本质上是裁剪 view 的 helper 类,让其初始化,并将 view 的实现分发到 GeneralRoundViewImpl

public class GeneralRoundImageView extends AppCompatImageView implements IRoundView {

private GeneralRoundViewImpl generalRoundViewImpl;

public GeneralRoundImageView(Context context) {

this(context, null);

}

public GeneralRoundImageView(Context context, @Nullable AttributeSet attrs) {

super(context, attrs);

init(this, context, attrs);

}

public GeneralRoundImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

init(this, context, attrs);

}

@Override

public void setCornerRadius(float cornerRadius) {

generalRoundViewImpl.setCornerRadius(cornerRadius);

}

@Override

public void onLayout(boolean changed, int left, int top, int right, int bottom) {

super.onLayout(changed, left, top, right, bottom);

generalRoundViewImpl.onLayout(changed, left, top, right, bottom);

}

private void init(GeneralRoundImageView view, Context context, AttributeSet attrs) {

generalRoundViewImpl = new GeneralRoundViewImpl(view,

context,

attrs,

R.styleable.GeneralRoundImageView,

R.styleable.GeneralRoundImageView_corner_radius);

}

}

  • 4、重写 dispatchDraw 方法,将实现类的方法包装 super

@Override

protected void dispatchDraw(Canvas canvas) {

generalRoundViewImpl.beforeDispatchDraw(canvas);

super.dispatchDraw(canvas);

generalRoundViewImpl.afterDispatchDraw(canvas);

}

  • 5、在你要使用的地方

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

尾声

评论里面有些同学有疑问关于如何学习material design控件,我的建议是去GitHub搜,有很多同行给的例子,这些栗子足够入门。

有朋友说要是动真格的话,需要NDK以及JVM等的知识,首现**NDK并不是神秘的东西,**你跟着官方的步骤走一遍就知道什么回事了,无非就是一些代码格式以及原生/JAVA内存交互,进阶一点的有原生/JAVA线程交互,线程交互确实有点蛋疼,但平常避免用就好了,再说对于初学者来说关心NDK干嘛,据鄙人以前的经历,只在音视频通信和一个嵌入式信号处理(离线)的两个项目中用过,嵌入式信号处理是JAVA->NDK->.SO->MATLAB这样调用的我原来MATLAB的代码,其他的大多就用在游戏上了吧,一般的互联网公司会有人给你公司的SO包的。
至于JVM,该掌握的那部分,相信我,你会掌握的,不该你掌握的,有那些专门研究JVM的人来做,不如省省心有空看看计算机系统,编译原理。

一句话,平常多写多练,这是最基本的程序员的素质,尽量挤时间,读理论基础书籍,JVM不是未来30年唯一的虚拟机,JAVA也不一定再风靡未来30年工业界,其他的系统和语言也会雨后春笋冒出来,但你理论扎实会让你很快理解学会一个语言或者框架,你平常写的多会让你很快熟练的将新学的东西应用到实际中。
初学者,一句话,多练。

包的。**
至于JVM,该掌握的那部分,相信我,你会掌握的,不该你掌握的,有那些专门研究JVM的人来做,不如省省心有空看看计算机系统,编译原理。

一句话,平常多写多练,这是最基本的程序员的素质,尽量挤时间,读理论基础书籍,JVM不是未来30年唯一的虚拟机,JAVA也不一定再风靡未来30年工业界,其他的系统和语言也会雨后春笋冒出来,但你理论扎实会让你很快理解学会一个语言或者框架,你平常写的多会让你很快熟练的将新学的东西应用到实际中。
初学者,一句话,多练。

由于文章篇幅问题复制链接查看详细文章以及获取学习笔记链接:前往我的GitHub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值