10. android 各种布局介绍

1. 在Android中的布局有五种:

1. FrameLayout(框架布局),

2. LinearLayout(线性布局)

3. RelativeLayout(相对布局)

4. TableLayout(表格布局)

5. AbsoluteLayout(绝对布局)

2. 在Android中,所有的View控件都是android.view.View继承的

3.创建视图的方法有两种:

1. 使用XML方式配置View的相关属性,然后装载这些View【直观,易于维护】

2. 完全使用Java代码创建View

4. 所有的布局文件必须放在res/layout目录中,布局文件的命名符合java规范便于生成R类中的索引。

5. 装载布局文件

1. 通常在onCreate方法中使用setContentView来制定要装载的XML布局文件。

6. 获取View控件

1. 使用findViewById(R.layout.xxxx),需要强赚为指定View的子类。

7.Android表示单位长度的方式通常由三种:

1. px:表示屏幕实际的像素,例如,320*480的屏幕在横向有320个像素。

2. dp(dip):是屏幕的物理尺寸。大小为1英寸的1/72

3. sp(与刻度无关的像素):与dp类似,但是可以根据用户的字体大小首选项进行缩放【字体 - 推荐】

8.实例【layout_margin_left / right / top / bottom】

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="150dp"
        android:text="@string/button1" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="150sp"
        android:paddingTop="150sp"
        android:text="@string/button1" />
    
        <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="30sp"
        android:paddingTop="20sp"
        android:gravity="right"
        android:layout_gravity="right"
        android:text="@string/button1" />

</LinearLayout>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值