博客
关于我
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当查询的时候有多个结果,但需要返回一条的情况用GROUP_CONCAT拼接
查看>>
MySQL必知必会(组合Where子句,Not和In操作符)
查看>>
MySQL必知必会总结笔记
查看>>
MySQL快速入门
查看>>
MySQL快速入门——库的操作
查看>>
mysql快速复制一张表的内容,并添加新内容到另一张表中
查看>>
mysql快速查询表的结构和注释,字段等信息
查看>>
mysql怎么删除临时表里的数据_MySQL中关于临时表的一些基本使用方法
查看>>
mysql性能优化
查看>>
mysql性能优化学习笔记-存储引擎
查看>>
MySQL性能优化必备25条
查看>>
Mysql性能优化(1):SQL的执行过程
查看>>
Mysql性能优化(2):数据库索引
查看>>
Mysql性能优化(3):分析执行计划
查看>>
Mysql性能优化(4):优化的注意事项
查看>>
Mysql性能优化(5):主从同步原理与实现
查看>>
Mysql性能优化(6):读写分离
查看>>
MySQL性能优化(八)--
查看>>
MySQL性能测试及调优中的死锁处理方法
查看>>
mysql性能测试工具选择 mysql软件测试
查看>>