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就好了

    以上代码效果图为:

  • 相关阅读:
    mvc:三
    mvc:二
    Linq分组,linq方法分组
    Linq 中按照多个值进行分组(GroupBy)
    Photoshop 字体
    报表Reporting S而vice是 错误的解决
    1*书籍装帧
    photoshop 魔术橡皮擦
    Photoshop 钢笔 双窗口显示
    数字格式化
  • 原文地址:https://www.cnblogs.com/niupi/p/13719735.html
Copyright © 2011-2022 走看看