zoukankan      html  css  js  c++  java
  • Android 代码写布局

     RelativeLayout relativeLayout = new RelativeLayout(this);
                relativeLayout.setId(R.id.num_layout);
                relativeLayout.setBackgroundColor(R.color.black);
                relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                
    //实例化一个TextView控件和设置属性 TextView textView
    = new TextView(this); textView.setId(R.id.num_textview); textView.setTextSize(18); textView.setTextColor(getResources().getColor(R.color.white)); String txt = "1 / 1"; textView.setText(txt); textView.setGravity(Gravity.CENTER);
    //给TextView添加位置布局 RelativeLayout.LayoutParams textLayout
    = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); textLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); textLayout.addRule(RelativeLayout.CENTER_HORIZONTAL); textLayout.setMargins(0,0,0,15);
    //加入到RelativeLayout的布局里 relativeLayout.addView(textView, textLayout);
    //实例化一个ImageView控件 ImageView imageView
    = new ImageView(this); //给ImageView控件添加布局位置信息 RelativeLayout.LayoutParams imageViewLayout = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); imageViewLayout.addRule(RelativeLayout.ABOVE, textView.getId()); imageViewLayout.addRule(RelativeLayout.CENTER_IN_PARENT); relativeLayout.addView(imageView, imageViewLayout);

    最后在代码中引用布局的地方,引入relativeLayout就好了

    以上代码效果图为:

  • 相关阅读:
    (68)zabbix windows性能计数器使用详解
    xenserver挂载新硬盘
    Centos7配置TiDB监控
    centos7下zabbix4.0配置磁盘IO监控
    XenServer7.6命令行导出导入虚拟机(迁移)
    Centos7修改分区空间
    Centos7安装xenserver tools
    Centos7配置TiDB集群
    Xenserver7.6修改root密码
    网络流量测试
  • 原文地址:https://www.cnblogs.com/niupi/p/13719735.html
Copyright © 2011-2022 走看看