博客
关于我
417_动态创建View
阅读量:164 次
发布时间:2019-02-28

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

动态创建View
    public static LinearLayout createRelativeLayout(Context context, LinearLayout linearLayout) {
        LinearLayout childLayout = new LinearLayout(context);
        childLayout.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.addView(childLayout);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childLayout.getLayoutParams();
        layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
        layoutParams.height = DensityUtil.dip2px(context, 35);
        childLayout.setLayoutParams(layoutParams);
        return childLayout;
    }
    public static TextView createTextView(Context context, LinearLayout linearLayout) {
        TextView textView = new TextView(context);
        linearLayout.addView(textView);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
        layoutParams.leftMargin = DensityUtil.dip2px(context, 16);
        textView.setLayoutParams(layoutParams);
        int dp5 = DensityUtil.dip2px(context, 5);
        int dp10 = DensityUtil.dip2px(context, 10);
        textView.setPadding(dp10, dp5, dp10, dp5);
        return textView;
    }

转载地址:http://rsac.baihongyu.com/

你可能感兴趣的文章
MYSQL数据库进阶操作
查看>>
MySQL数据库配置文件调优详解
查看>>
MySQL数据库酒店客房管理系统(含MySQL源码) 结课作业 做的不是很好
查看>>
mysql数据库里的一些坑(读高性能mysql有感)
查看>>
MySQL数据库面试题(2021最新版)
查看>>
MySQL数据库高并发优化配置
查看>>
mysql数据恢复
查看>>
MySQL数据的主从复制、半同步复制和主主复制详解
查看>>
mysql数据碎片整理
查看>>
MySQL数据类型
查看>>
MySQL数据类型字节长度
查看>>
mysql数据被误删的恢复方案
查看>>
MySQL数据读写分离(MaxScale)上干货!!!
查看>>
mysql整库导入、导出
查看>>
mysql文本函数和数字函数
查看>>
Mysql新建用户和数据库并授权
查看>>
mysql日志
查看>>
mysql日志 事务问题_mysql因为事务日志问题无法启动
查看>>
mysql日志文件
查看>>
mysql日志管理学习笔记
查看>>