常用的ui布局

UI常用的布局
LineaLayout:
线性布局
重要属性:
-orientation方向 分为水平,垂直
-layout-Weight(权重)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="To"
        >
    </EditText>


    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         android:hint="Subject"
         />


    <EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="massage"
        />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        
        >


        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="reset" 
            
            android:layout_weight="1"
            />


        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            
            android:text="send"
             android:layout_weight="1"
            
            />


    </LinearLayout>


</LinearLayout>

----------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <EditText
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       android:layout_margin="20dp"
        android:paddingLeft="60dp"
       android:hint="Message"
      
        
        />


    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/textView1"
       android:layout_below="@+id/textView1"
      
        android:layout_marginTop="20dp"
        android:text="OK" />


</RelativeLayout>


-------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TableRow 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView 
         android:layout_width="0dp"
        android:layout_height="wrap_content"
            android:text="1241"
            android:gravity="center"
            android:layout_weight="1"
            />
        <TextView 
         android:layout_width="0dp"
        android:layout_height="wrap_content"
            android:text="哈哈"
            android:gravity="center"
            android:layout_weight="1"
            />
       
        
    </TableRow>
        <TableRow 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView 
         android:layout_width="0dp"
        android:layout_height="wrap_content"
            android:text="1241"
            android:gravity="center"
            android:layout_weight="1"
            />
        <TextView 
         android:layout_width="0dp"
        android:layout_height="wrap_content"
            android:text="哈哈"
            android:gravity="center"
            android:layout_weight="1"
            />
       
        
    </TableRow>


</TableLayout>


------------------------------------------------------------------------------------------------------------------

线性布局: 用来控制其View以水平或垂直方式展开显示

重要属性:

orientation(方向)

layout_weight(权重)

理解LinearLayout权重

layout_weight(权重)的值

=0( 默认值 ): 指定多大空间就占据多大的空间
>0:   将父视图中的 可用空间进行分割 , 值越大 权重就越大 , 占据的 比例就会越大

Layout_weight的使用场景

将布局的宽度或高度 平均分成几个等份
垂直方向上占用 中间所有空间 或水平方向上占用中间所有空间


RelativeLayout

相对布局: 用来控制其子View相对定位的方式进行布局显示

相对布局是最灵活, 最强大,也是学习难度最大的布局

相对布局相关属性比较多:

兄弟视图 之间 : 同方向对齐 , 反方向对齐
与父视图 之间 : 同方向对齐 , 居中


FrameLayout

帧布局中的 每一个子 View 都代表一个画面 ,默认以屏幕左上角作为( 0,0 )坐标,按定义的先后顺序依次逐屏显示, 后面出现的会覆盖前面的画面 ,
通过子 View android: layout_gravity   属性来指定子视图的位置

属性划分

针对任何View的属性
常用的最基本属性
内边距属性 padding
外边距属性 margin
只针对RelativeLayout的属性
反方对齐属性to/above/below
同方向对齐属性 align
相对父视图的属性 alignparent/center
只针对LinearLayout的属性
权重属性 weight
方向属性 oritation


常用基本属性


内边距与外边距

内边距属性



外边距属性

相对兄弟视图定位

 


相对父视图定位

-----------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView 
        android:layout_width="280dp"
        android:layout_height="280dp"
        android:background="#33FFFF"
        android:layout_gravity="center"
        />
    <TextView 
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:background="#33CCFF"
        android:layout_gravity="center"
        />


    <TextView 
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:background="#3399FF"
        android:layout_gravity="center"
        />
    <TextView 
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:background="#3366FF"
        android:layout_gravity="center"
        />
    <TextView 
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#3300FF"
        android:layout_gravity="center"
        />

</FrameLayout>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值