Android线性布局五角示例

LinearLayout线性布局

元素属性:

                  gravity="left"(是本元素所有子元素的对齐方式,设置在父元素上,可设置多个值,多个值用|符号隔开

                  layout_gravity (子元素在父元素的对齐方式,设置在子元素上)

                  orientation="vertical"  时, 只有水平方向的设置才起作用。垂直分布
                  orientation="horizontal" 时, 只有垂直方向的设置才起作用。水平分布

                  wrap_parent:匹配自身长宽

                  match_parent:匹配父长宽,也就是整个显示屏幕

                  fill_parent:填充屏幕长宽

  实现关键点:(线性布局嵌套,layout_weight权重比)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.10"
        android:gravity="left"
        android:orientation="vertical"
        >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮2"
            android:layout_marginTop="400dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="2.49"
        android:gravity="center"
        android:orientation="vertical"
        >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮3"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="0.33"
        android:gravity="right"
        >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮4"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮5"
            android:layout_marginTop="400dp"/>

    </LinearLayout>

</LinearLayout>

 注:在使用layout_weight权重分比时,多注意值大小的分配。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值