zoukankan      html  css  js  c++  java
  • android_layout_relativelayout(二)

    官网上的一个xml文件:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent">
    <TextView
    android:id="@+id/label"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:text
    ="Type here:"/>
    <EditText
    android:id="@+id/entry"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:background
    ="@android:drawable/editbox_background"
    android:layout_below
    ="@id/label"/>
    <Button
    android:id="@+id/ok"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_below
    ="@id/entry"
    android:layout_alignParentRight
    ="true"
    android:layout_marginLeft
    ="10dip"
    android:text
    ="OK" />
    <Button
    android:layout_width="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_toLeftOf
    ="@id/ok"
    android:layout_alignTop
    ="@id/ok"
    android:text
    ="Cancel" />
    </RelativeLayout>

    效果图可以看官网,问题在于,xml文件规定这个cancel按钮在ok按钮的左边,但是没有说左到什么程度。从实际效果来看,仅仅是在ok按钮的左边一点点。那么,为什么cancel按钮不左的彻底一点,在一行的开头呢?

    我做个试验:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent">
    <TextView
    android:id="@+id/label"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:text
    ="Type here:"/>
    <EditText
    android:id="@+id/entry"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:background
    ="@android:drawable/editbox_background"
    android:layout_below
    ="@id/label"/>
    <Button
    android:id="@+id/ok"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_below
    ="@id/entry"
    android:layout_alignParentRight
    ="true"
    android:layout_marginLeft
    ="10dip"
    android:text
    ="OK" />
    <Button
    android:layout_width="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_alignTop
    ="@id/ok"
    android:text
    ="Cancel" />
    </RelativeLayout>

    效果就是,此时cancel按钮虽然在ok按钮的左边,但是左的很彻底,在一行的最左边,与上一个xml文件仅仅相差一个

    android:layout_toLeftOf="@id/ok"
    个人认为这个属性默认两个控件之间相差一个默认值。
    扛不住了,再来一个
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent">
    <TextView
    android:id="@+id/label"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:text
    ="Type here:"/>
    <EditText
    android:id="@+id/entry"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:background
    ="@android:drawable/editbox_background"
    android:layout_below
    ="@id/label"/>
    <Button
    android:id="@+id/ok"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_below
    ="@id/entry"
    android:layout_alignParentRight
    ="true"
    android:layout_marginLeft
    ="10dip"
    android:text
    ="OK" />
    <Button
    android:layout_width="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_alignTop
    ="@id/ok"
    android:layout_toLeftOf
    ="@id/ok"
    android:layout_marginRight
    ="50dip"
    android:text
    ="Cancel" />
    </RelativeLayout>

    我硬是将cancel离右边距50个dip,也只是离ok按钮远了一点。
    突然觉得,布局的属性之间,可以人为的设置一些矛盾的属性。



  • 相关阅读:
    return 与 exit() 的区别
    RtlInitUnicodeString
    计算机网络 学习笔记-概论
    STM32学习笔记(五) USART异步串行口输入输出(轮询模式)
    STM32学习笔记(四) RCC外设的学习和理解
    简单RTOS学习(一) uc/os-II 工程模板建立
    web前端学习(一) html+js实现文本框背景及只读属性修改
    TCP/IP协议学习(一) LWIP实现网络远程IAP下载更新
    STM32学习笔记(三) STM32的GPIO的深入学习
    STM32学习笔记(二) 基于STM32-GPIO的流水灯实现
  • 原文地址:https://www.cnblogs.com/itblog/p/7236641.html
Copyright © 2011-2022 走看看