A015-布局之LinearLayout

eg: layout_linearlayout.xml

<?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”>

<Button

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“我是按钮1”

android:id="@+id/button" />

<B

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

浏览器打开:qq.cn.hn/FTe 免费领取

utton

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“我是按钮2”

android:id="@+id/button2" />

<Button

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“我是按钮3”

android:id="@+id/button3" />

效果图:

Vertical

eg:

<?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=“horizontal”>

<Button

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“我是按钮1”

android:id="@+id/button" />

<Button

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“我是按钮2”

android:id="@+id/button2" />

<Button

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“我是按钮3”

android:id="@+id/button3" />

效果图:

horizontal

解析一下上面用到的属性:

ID

任意一个View都可能伴随着一个整形类型的ID唯一标识这个View,这个属性是通用属性,只要有需要的时候都可以为View定义相应的ID,然而这个整形ID会映射到R.java文件中,如下图所示:

ID

Layout Parameters


布局属性,我们在上面所用到的layout_width、layout_height分别代表宽度、高度属性。每一个View都必须定义它,你可以为View指定精确的数值,一般以dp为单位,但一般我们都会指定宽高为以下这两个值:

- wrap_cotent(告诉你的view调整自己到内容所要求的尺寸)

- match_parent(告诉你的view变得跟它的parent view group所能允许的最大尺寸一样)

layout_weight


这个是LinearLayout的一个重要属性,权重。它可以指定View占据多大的空间,权重越大占的空间就越大,如果不设默认为0.

eg:

<?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”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用:3.sorted()方法和list.sort()方法有什么区别? list = ["hello","hey","hi","allow","consent","approve"] print(list) print("-"*100) list_sorted = sorted(list) print(list_sorted) print("-"*100) print(list) list_sort = list.sort() print(list) print(list_sort()) ['hello', 'hey', 'hi', 'allow', 'consent', 'approve'] ---------------------------------------------------------------------------------------------------- ['allow', 'approve', 'consent', 'hello', 'hey', 'hi'] ---------------------------------------------------------------------------------------------------- ['hello', 'hey', 'hi', 'allow', 'consent', 'approve'] ['allow', 'approve', 'consent', 'hello', 'hey', 'hi'] --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-26-b80c1a015c3a> in <module>() 8 list_sort = list.sort() 9 print(list) ---> 10 print(list_sort()) TypeError: 'NoneType' object is not callable 。引用:2.字典是可迭代的吗? for i in t: print(i) print("-"*100) for i in t.keys(): print(i) print("-"*100) for i in t.values(): print(i) print("-"*100) for i in t.items(): print(i) year month day hour minute second ---------------------------------------------------------------------------------------------------- year month day hour minute second ---------------------------------------------------------------------------------------------------- 2018 12 4 21 52 20 ---------------------------------------------------------------------------------------------------- ('year', '2018') ('month', '12') ('day', '4') ('hour', '21') ('minute', '52') ('second', '20') 。引用:1.如何取得字典中的键和值? t = {'year':'2018','month':'12','day':'4','hour':'21','minute':'52','second':'20'} print(t.keys()) print(t.values()) print(t.items()) dict_keys(['year', 'month', 'day', 'hour', 'minute', 'second']) dict_values(['2018', '12', '4', '21', '52', '20']) dict_items([('year', '2018'), ('month', '12'), ('day', '4'), ('hour', '21'), ('minute', '52'), ('second', '20')]) 。Python FAQ Q: sorted()方法和list.sort()方法有什么区别? A: sorted()方法和list.sort()方法都可以对列表进行排序,但是它们有一些区别。sorted()方法会返回一个新的已排序的列表,而不会修改原始列表。而list.sort()方法会直接修改原始列表,但不返回任何值。此外,list.sort()方法只能用于列表,而sorted()方法可以用于任何可迭代对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值