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>

更多相关文章

  1. android 安装软件
  2. 设置 Toolbar(ActionBar) 上的按钮颜色
  3. Android的自定义长按
  4. Android(安卓)GPS两点间距离
  5. Android发送短信功能代码
  6. 反抗金山毒霸的代码
  7. Listview Section 多个标题以及内容
  8. Android(安卓)代码混淆 选项说明
  9. Android应用程序组件Content Provider的启动过程源代码分析(2)

随机推荐

  1. Android中自定义View仿京东秒杀倒计时
  2. Android:adb shell am命令行发送Activity
  3. GridView做所有程序主菜单
  4. Android(安卓)IOS平台AE动画库
  5. 2013.08.30——— android 关于OAuth 2.0
  6. Android(安卓)技术博客汇总
  7. android webview字体大小的控制
  8. 四十七、实现调用Android手机的拍照功能
  9. 获取android手机基本信息
  10. 介绍一个Android开源项目:GifView——Andr