Android UI开发(2)

线性布局的使用

  利用所学的UI开发方面的知识完成如下界面:


打开AndroidStudio开发环境,建立LinearLayout文件,其图一界面代码如下:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="20dp"
    android:orientation="vertical"

    
>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000"
        android:layout_weight="1"
        
/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f00"
        android:layout_weight="1"
        android:layout_marginTop="20dp"

        
/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff0"
        android:layout_weight="1"
        android:layout_marginTop="20dp"
        
/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f0f"
        android:layout_weight="1"
        android:layout_marginTop="20dp"
        
/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#f0f1"
        android:layout_weight="1"
        android:layout_marginTop="20dp"
        
/>

</LinearLayout>



其中

android:padding="20dp"含义是所建控件相对于布局上下左右均存在20dp的空间

android:layout_wight="1"运用权重使控件符合布局

android:layout_marginTop="20dp"表示离某元素上边缘的距离

android:background="#f0f1"界面中的元素的颜色属性,通过修改"#"后边的数值改变颜色的配色方案

最后呈现出的界面图如下:



现在进行图二所示界面的编辑,同样的打开AndroidStudio开发环境,建立LinearLayout文件,其代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    
>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="To"
        
/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Subject"
        
/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Message"
        android:layout_weight="1"
        
/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Send"
        android:layout_gravity="bottom"
        android:gravity="right"
        
/>


</LinearLayout>


同样的这其中也运用权重使控件符合布局,能适应不同尺寸的界面。

其界面最终呈现效果如下:


这样我们就按照要求完成了线性布局的简单应用,相信在以后的学习过程中 会在更多的方面用到线性布局方面的知识。






  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值