zoukankan      html  css  js  c++  java
  • RelativeLayout用代码兑现布局

    RelativeLayout用代码实现布局
    TextView txt1 = new TextView(this);  
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,  
        LayoutParams.WRAP_CONTENT);  
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);  

        params.addRule(RelativeLayout.LEFT_OF, 1001);  
        txt1.setLayoutParams(params);

        TextView txt2 = new TextView(this);  
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams. WRAP_CONTENT,  
        LayoutParams.WRAP_CONTENT);  
        params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
        txt2.setLayoutParams(params2);  
        txt2.setText("obj");
        txt2.setId(1001);  
        
        RelativeLayout layout1 = new RelativeLayout(this);  
        layout1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  
        layout1.addView(txt1);  
        layout1.addView(txt2);  
        setContentView(layout1);



    对应的XML:
    <RelativeLayout  
        xmlns:android="http://schemas.android.com/apk/res/android"  
        android:layout_height="fill_parent"  
        android:layout_width="fill_parent">  
        <TextView  
            android:id="@+id/leftobj"  
            android:hint="left of the base"  
            android:layout_alignParentLeft="true"  
            android:layout_width="fill_parent"  
            android:layout_toLeftOf="@+id/base"  
            android:layout_height="wrap_content"></TextView>  
        <TextView 
            android:id="@+id/base" 
            android:text="obj"  
            android:layout_width="wrap_content"  
            android:layout_alignParentRight="true"  
            android:layout_height="wrap_content"></TextView>  
    </RelativeLayout>

  • 相关阅读:
    Photoshop教程,视频MP4格式转换为GIF格式
    pyqgis环境配置
    R 输出函数 格式化输出 打印函数
    linux ubuntu 更改终端的默认设置,终端大小,字体
    wps 显示所有的字符,将参考文献排序,插入目录
    在 word 中 怎么让表格旋转方向
    linux argc argv
    linux 命令行的快捷键 vim
    linux 操作系统,以及一般的操作系统 所看书籍
    win 10 快速启动 某些程序
  • 原文地址:https://www.cnblogs.com/kobe8/p/3860721.html
Copyright © 2011-2022 走看看