• Android学习笔记-----------布局(二)


    RelativeLayout(相对布局)

    相对布局也是android开发中常用的布局.布局同一个界面,相对于线性布局,相对布局嵌套的层数少,性能更佳.

    相对布局,顾名思义就是相对于其他的控件进行布局.可以通过同级控件制定位置,也可以通过父级控件指定位置.

    在相对布局中具有以下属性可以对控件进行布局:

    1.android:layout_below 表示当前控件位于指定id控件的下方
    2.android:layout_above 表示当前控件位于指定id控件的上方
    3.android:layout_toRightOf 表示当前控件位于指定id控件的右方
    4.android:layout_toLeftOf 表示当前控件位于指定id控件的左方
    5.android:layout_alignTop 表示当前控件与指定id控件顶部对齐
    6.android:layout_alignBottom 表示当前控件与指定id控件底部对齐
    7.android:layout_alignLeft 表示当前控件与指定id控件左侧对齐
    8.android:layout_alignRight 表示当前控件与指定id控件右侧对齐
    9.android:layout_alignBaseline 表示当前控件与指定id控件基线对齐
    10.android:layout_centerHorizonta l如果指定true表示在父布局水平居中位置
    11.android:layout_centerVertical 如果指定true表示在父布局竖直居中位置
    12.android:layout_centerInParent 如果指定true表示在父布局竖直水平位置居中
    13.android:layout_alignParentTop 如果指定为true表示位于父布局的顶部位置
    14.android:layout_alignParentBottom 如果指定为true表示位于父布局的底部位置
    15.android:layout_alignParentLeft 如果指定为true表示位于父布局的左侧位置
    16.android:layout_alignParentRight 如果指定为true表示位于父布局的右侧位置

    以下通过一个demo来总结

    效果如下

      1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      2     xmlns:tools="http://schemas.android.com/tools"
      3     android:layout_width="match_parent"
      4     android:layout_height="match_parent"
      5     android:background="@drawable/guide_login_bg"
      6       >
      7     <ImageView 
      8         android:id="@+id/iv_login"
      9         android:layout_width="wrap_content"
     10         android:layout_height="wrap_content"
     11         android:layout_centerHorizontal="true"
     12         android:background="@drawable/no_login_head"
     13         />
     14     <TextView
     15         android:id="@+id/tv_login" 
     16         android:layout_width="wrap_content"
     17         android:layout_height="wrap_content"
     18         android:layout_below="@id/iv_login"
     19         android:layout_centerHorizontal="true"
     20         android:text="登陆"
     21         android:textSize="20sp"
     22         android:textColor="#ffffff"
     23         />
     24     <TextView 
     25         android:id="@+id/tv_line1"
     26         android:layout_width="match_parent"
     27         android:layout_height="1dp"
     28         android:background="#ffffff"
     29         android:layout_below="@id/tv_login"
     30         />
     31     <RelativeLayout 
     32         android:id="@+id/rl_collect"
     33         android:layout_width="wrap_content"
     34         android:layout_height="wrap_content"
     35         android:layout_below="@id/tv_line1"
     36         >
     37     <ImageView 
     38         android:id="@+id/iv_collect"
     39         android:layout_width="wrap_content"
     40         android:layout_height="wrap_content"
     41         android:layout_alignParentLeft="true"
     42         android:layout_centerVertical="true"
     43         android:background="@drawable/icn_01"
     44         />
     45     <TextView
     46         android:id="@+id/tv_collect" 
     47         android:layout_width="wrap_content"
     48         android:layout_height="wrap_content"
     49         android:layout_toRightOf="@id/iv_collect"
     50         android:layout_centerVertical="true"
     51         android:text="我的收藏"
     52         android:textSize="16sp"
     53         android:textColor="#ffffff"
     54         />
     55     </RelativeLayout>
     56     <TextView 
     57         android:id="@+id/tv_line2"
     58         android:layout_width="match_parent"
     59         android:layout_height="1dp"
     60         android:background="#ffffff"
     61         android:layout_below="@id/rl_collect"
     62         />
     63     <RelativeLayout 
     64         android:id="@+id/rl_message"
     65         android:layout_width="wrap_content"
     66         android:layout_height="wrap_content"
     67         android:layout_below="@id/tv_line2"
     68         >
     69     <ImageView 
     70         android:id="@+id/iv_message"
     71         android:layout_width="wrap_content"
     72         android:layout_height="wrap_content"
     73         android:layout_alignParentLeft="true"
     74         android:layout_centerVertical="true"
     75         android:background="@drawable/icn_02"
     76         />
     77     <TextView
     78         android:id="@+id/tv_message" 
     79         android:layout_width="wrap_content"
     80         android:layout_height="wrap_content"
     81         android:layout_toRightOf="@id/iv_message"
     82         android:layout_centerVertical="true"
     83         android:text="我的消息"
     84         android:textSize="16sp"
     85         android:textColor="#ffffff"
     86         />
     87     </RelativeLayout>
     88     <TextView 
     89         android:id="@+id/tv_line3"
     90         android:layout_width="match_parent"
     91         android:layout_height="1dp"
     92         android:background="#ffffff"
     93         android:layout_below="@id/rl_message"
     94         />
     95     <RelativeLayout 
     96         android:id="@+id/rl_set"
     97         android:layout_width="wrap_content"
     98         android:layout_height="wrap_content"
     99         android:layout_below="@id/tv_line3"
    100         >
    101     <ImageView 
    102         android:id="@+id/iv_set"
    103         android:layout_width="wrap_content"
    104         android:layout_height="wrap_content"
    105         android:layout_alignParentLeft="true"
    106         android:layout_centerVertical="true"
    107         android:background="@drawable/icn_03"
    108         />
    109     <TextView
    110         android:id="@+id/tv_set" 
    111         android:layout_width="wrap_content"
    112         android:layout_height="wrap_content"
    113         android:layout_toRightOf="@id/iv_set"
    114         android:layout_centerVertical="true"
    115         android:text="我的設置"
    116         android:textSize="16sp"
    117         android:textColor="#ffffff"
    118         />
    119     </RelativeLayout>
    120     <TextView 
    121         android:id="@+id/tv_line4"
    122         android:layout_width="match_parent"
    123         android:layout_height="1dp"
    124         android:background="#ffffff"
    125         android:layout_below="@id/rl_set"
    126         />
    127     <RelativeLayout 
    128         android:id="@+id/rl_view"
    129         android:layout_width="wrap_content"
    130         android:layout_height="wrap_content"
    131         android:layout_below="@id/tv_line4"
    132         >
    133     <ImageView 
    134         android:id="@+id/iv_view"
    135         android:layout_width="wrap_content"
    136         android:layout_height="wrap_content"
    137         android:layout_alignParentLeft="true"
    138         android:layout_centerVertical="true"
    139         android:background="@drawable/icn_04"
    140         />
    141     <TextView
    142         android:id="@+id/tv_view" 
    143         android:layout_width="wrap_content"
    144         android:layout_height="wrap_content"
    145         android:layout_toRightOf="@id/iv_view"
    146         android:layout_centerVertical="true"
    147         android:text="意見反饋"
    148         android:textSize="16sp"
    149         android:textColor="#ffffff"
    150         />
    151     </RelativeLayout>
    152     <TextView 
    153         android:id="@+id/tv_line5"
    154         android:layout_width="match_parent"
    155         android:layout_height="1dp"
    156         android:background="#ffffff"
    157         android:layout_below="@id/rl_view"
    158         />
    159     <RelativeLayout 
    160         android:id="@+id/rl_new"
    161         android:layout_width="wrap_content"
    162         android:layout_height="wrap_content"
    163         android:layout_below="@id/tv_line5"
    164         >
    165     <ImageView 
    166         android:id="@+id/iv_new"
    167         android:layout_width="wrap_content"
    168         android:layout_height="wrap_content"
    169         android:layout_alignParentLeft="true"
    170         android:layout_centerVertical="true"
    171         android:background="@drawable/icn_05"
    172         />
    173     <TextView
    174         android:id="@+id/tv_new" 
    175         android:layout_width="wrap_content"
    176         android:layout_height="wrap_content"
    177         android:layout_toRightOf="@id/iv_new"
    178         android:layout_centerVertical="true"
    179         android:text="更新軟件"
    180         android:textSize="16sp"
    181         android:textColor="#ffffff"
    182         />
    183     </RelativeLayout>
    184     <TextView 
    185         android:id="@+id/tv_line6"
    186         android:layout_width="match_parent"
    187         android:layout_height="1dp"
    188         android:background="#ffffff"
    189         android:layout_below="@id/rl_new"
    190         />
    191     <RelativeLayout 
    192         android:id="@+id/rl_us"
    193         android:layout_width="wrap_content"
    194         android:layout_height="wrap_content"
    195         android:layout_below="@id/tv_line6"
    196         >
    197     <ImageView 
    198         android:id="@+id/iv_us"
    199         android:layout_width="wrap_content"
    200         android:layout_height="wrap_content"
    201         android:layout_alignParentLeft="true"
    202         android:layout_centerVertical="true"
    203         android:background="@drawable/icn_06"
    204         />
    205     <TextView
    206         android:id="@+id/tv_us" 
    207         android:layout_width="wrap_content"
    208         android:layout_height="wrap_content"
    209         android:layout_toRightOf="@id/iv_us"
    210         android:layout_centerVertical="true"
    211         android:text="關於我們"
    212         android:textSize="16sp"
    213         android:textColor="#ffffff"
    214         />
    215     </RelativeLayout>
    216 </RelativeLayout>
  • 相关阅读:
    解决部分小程序无法获取UnionId的问题
    你也可以写个聊天程序
    JavaScript 数据结构与算法之美
    CSS content应用
    JS中判断null、undefined与NaN的方法
    IT资料常用网址汇总
    史上最全的正则表达式-匹配中英文、字母和数字
    百万数据修改索引,百万数据修改主键
    SQL Server 2005 实现数据库同步备份 过程--结果---分析
    数据库性能优化三:程序操作优化
  • 原文地址:https://www.cnblogs.com/Jhope/p/5280728.html
Copyright © 2020-2023  润新知