博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android自定义控件CustomView2 扩展控件、组合控件
阅读量:7066 次
发布时间:2019-06-28

本文共 970 字,大约阅读时间需要 3 分钟。

  hot3.png

1.init() {

    post(...) {

        setBitmap(...);        //    自定义Imageview

    }

}

2.组合控件

public class MyLinearViewGroup extends LinearLayout {

    init() {

        ...

        getContext();

        

        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);

        params.addRule(ALIGN_PARENT_BOTTOM);

        button.setLayoutParams(params);

 

        addView(button);    //    每个ViewGroup类的控件都有该方法,动态添加子控件或子布局

    }

}

 

View.setTag("...");

 

3.自定义属性

res/values    ——>    attrs

<resources>

    <declare-styleable name="MyLinearViewGroup">

        <attr name="myText" format="String"/>

        <attr name="myColor" format="color"/>

    </declare-styleable>

</resources>

 

<RelativeLayout

    ...

    appNs

    ...>

    <com.xxx.MyLinearViewGroup

        ...

        app:myText="..."

        app:myColor="#f00"/>

</RelativeLayout>

 

init(Context context, AttributeSet attrs) {

    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MyLinearViewGroup);

    String text = array.getString(R.styleable.MyLinearViewGroup_myText);

}

转载于:https://my.oschina.net/glfei/blog/3027881

你可能感兴趣的文章
mysql中查询语句中的一个知识点说明
查看>>
直接用postman测试api ,服务器端没提供跨域也可以访问。
查看>>
IE8不能保存cookie,造成response.redirect死循环的原因
查看>>
PHP:第六章——正则表达式的基本概念
查看>>
nginx压缩,缓存
查看>>
运营社群看这篇就够了,微信群门槛设置,用户思维、流量思维与产品思维
查看>>
centos彻底删除文件夹、文件命令
查看>>
软件过程
查看>>
脚本监控2个进程有进程死掉重启进程
查看>>
Mac下开机启动rc.common不生效的问题
查看>>
HQL的select new map ···语法
查看>>
牛逼的 弹出层 layer !!!
查看>>
mysql中OPTIMIZE TABLE的作用
查看>>
nslookup工具的使用方法
查看>>
决策树-过程
查看>>
Android适配底部返回键等虚拟键盘的完美解决方案
查看>>
byte[]数组的正则表达式搜索 z
查看>>
jquery获取表单数据方法$.serializeArray()获取不到disabled的值
查看>>
【Android Studio安装部署系列】二十七、Android studio修改项目名称和包名
查看>>
【M15】了解异常处理(exception handling)的成本
查看>>