• Android布局管理器


    Android中的布局包括
    :线性布局、表格布局、相对布局、帧布局和绝对布局;


    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led2off" android:id="@+id/btnLED2Off" android:layout_weight="1" android:layout_alignParentRight="true" android:layout_marginLeft="10px" ></Button> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led1off" android:id="@+id/btnLED1Off" android:layout_weight="0.1" android:layout_toLeftOf="@id/btnLED2Off" ></Button> <Button android:layout_height="wrap_content" android:text="@string/led1on" android:layout_width="wrap_content" android:id="@+id/btnLED1On" android:layout_weight="1" android:layout_toLeftOf="@id/btnLED1Off" ></Button> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led2on" android:id="@+id/btnLED2On" android:layout_weight="1" android:layout_toLeftOf="@id/btnLED1On" android:layout_alignTop="@id/btnLED2Off" ></Button> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led3off" android:id="@+id/btnLED3Off" android:layout_weight="1" android:layout_below="@id/btnLED2Off" ></Button> <Button android:layout_height="wrap_content" android:text="@string/led3on" android:layout_width="wrap_content" android:id="@+id/btnLED3On" android:layout_weight="1" android:layout_below="@id/btnLED3Off" ></Button> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led4on" android:id="@+id/btnLED4On" android:layout_weight="1" android:layout_below="@id/btnLED3On" ></Button> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led4off" android:id="@+id/btnLED4Off" android:layout_weight="1" android:layout_below="@id/btnLED4On" ></Button> <!-- 我的注释--> <!--android:layout_alignParentTop="true"--> <!--android:layout_alignParentLeft="true"--> <!--android:layout_marginTop="295dp"--> </RelativeLayout>

    上面的代码就是界面布局的XML语句;

    主要是调整位置;

    </RelativeLayout>这个表示 相对布局;

    android:layout_width="wrap_content" //按钮大小适应字体大小
    android:layout_height="wrap_content"//按钮大小适应字体大小

    android:layout_alignParentRight="true" //靠在父窗口的最右边

    android:layout_toLeftOf="@id/btnLED2Off"//靠在按钮LED2OFF的左边

    android:layout_below="@id/btnLED2Off"//靠在按钮LED2OFF下边

    控件类:

    看来写博客确实耐心,我还是记录些代码吧:

     最后调整后的代码如下:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led2off" android:id="@+id/btnLED2Off"
                android:layout_weight="1" android:layout_alignParentRight="true"
                android:layout_marginLeft="10px"
        ></Button>
    
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led1off" android:id="@+id/btnLED1Off"
                android:layout_weight="0.1" android:layout_toLeftOf="@id/btnLED2Off"
                android:layout_marginLeft="10px"
        ></Button>
    
        <Button android:layout_height="wrap_content" android:text="@string/led1on" android:layout_width="wrap_content" android:id="@+id/btnLED1On"
                android:layout_weight="1" android:layout_toLeftOf="@id/btnLED1Off"
                android:layout_marginLeft="10px"
        ></Button>
    
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led2on" android:id="@+id/btnLED2On"
                android:layout_weight="1" android:layout_toLeftOf="@id/btnLED1On"
                android:layout_marginLeft="10px"
        ></Button>
    
    
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led3off" android:id="@+id/btnLED3Off"
                android:layout_weight="1" android:layout_below="@id/btnLED2Off"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10px"
        ></Button>
    
        <Button android:layout_height="wrap_content" android:text="@string/led3on" android:layout_width="wrap_content" android:id="@+id/btnLED3On"
                android:layout_weight="1"
                android:layout_toLeftOf="@id/btnLED3Off"
                android:layout_below="@id/btnLED2Off"
                android:layout_marginLeft="10px"
        ></Button>
    
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led4on" android:id="@+id/btnLED4On"
                android:layout_weight="1" android:layout_toLeftOf="@id/btnLED3On"
                android:layout_below="@id/btnLED1Off"
                android:layout_marginLeft="10px"
        ></Button>
    
        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/led4off" android:id="@+id/btnLED4Off"
                android:layout_weight="1"
                android:layout_below="@id/btnLED2On"
                android:layout_toLeftOf="@id/btnLED4On"
        ></Button>
    
        <!-- 我的注释-->
        <!--android:layout_alignParentTop="true"-->
        <!--android:layout_alignParentLeft="true"-->
        <!--android:layout_marginTop="295dp"-->
    
    </RelativeLayout>
    
  • 相关阅读:
    架构师技能图谱 V1.2
    CTO 技能图谱
    物联网的技术构架
    东进交换机
    Ipad2
    ipad2 恢复
    论文建议
    SQL归档
    SQL 会议消费记录统计
    javascript中的方法:类方法(静态方法)对象方法 原型方法
  • 原文地址:https://www.cnblogs.com/tao560532/p/3263791.html
Copyright © 2020-2023  润新知