Android移动应用开发_基础页面布局总结

LinearLayout布局(线性布局),有方向的线性布局
重要属性:android:orientation,值:horizontal(水平方向),vertical(垂直方向
LinearLayout相当于html中的div(盒子),所以LinearLayout里也可以放入多个LinearLayout
代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"><!--布局方向 “垂直”-->

</LinearLayout>

这里面:
android:layout_width="match_parent"指的是当前的线性布局宽度占整个父元素,这里相对于当前的线性布局父元素为当前的窗体,所以宽度占满窗体
android:layout_height="match_parent"指的是当前的线性布局高度占整个父元素,这里相对于当前的线性布局父元素为当前的窗体,所以高度占满窗体
也可以自定义,如“200dp”:
android:layout_width=“200dp”
android:layout_height=“200dp”
‘dp’作为这里的像素单位
设置宽度和高度的值除了自定义、“match_parent(占满)”还有“wrap_content(随内容而定)”
代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"><!--布局方向 “垂直”-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#cccccc">
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#ffffff">
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#f62d59">
    </LinearLayout>

</LinearLayout>

效果图:
在这里插入图片描述
下面是LinearLayout布局(线性布局)中水平方向的布局样式,
android:orientation="horizontal"

代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"><!--布局方向 “垂直”-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#cccccc"
        android:orientation="horizontal"><!--布局方向 "水平"-->

        <LinearLayout
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#000000">
        </LinearLayout>
        <LinearLayout
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#BDB76B">
        </LinearLayout>
        <LinearLayout
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#FFFACD">
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#ffffff">
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#f62d59">
    </LinearLayout>
</LinearLayout>

效果图:
在这里插入图片描述
两者线性布局在实践项目中都尤其重要,比如简单的登录页面:
在这里插入图片描述
在大体的线性布局样式确定的情况下,加入一些文本标签(TextView)、按钮标签(Button)、文本输入框(EditText)等等添加属性修饰即可

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值