继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

android_day2_Layout

米脂
关注TA
已关注
手记 492
粉丝 88
获赞 590

布局一:初识Layout

<!--

  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"  布局的高,就是手机屏幕的高

     match_parent:填充父控件(因为RelativeLayout已经是最外层,即父控件就是手机屏幕)

     wrap_content:内容包裹(随着控件里面的内容的变化而变化)

     padding:就是控件边缘到控件里内容的距离,即内边距

     Layout_margin:就是控件边缘到另一个控件的距离,即外边距

     android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

      android:paddingRight="@dimen/activity_horizontal_margin"

   android:paddingTop="@dimen/activity_vertical_margin"

         android:background="#5f0000": 背景颜色

android:orientation="vertical":控制控件垂直方向,一行只能就放一个控件(或者一个布局)

android:orientation=:horizontal:水平方向排列,一列就只能放一个控件(或者一个布局)

LinearLayout 线性布局默认方向为水平

android:id:给控件添加ID,会在R.java文件中自动生成一个id值,目的是方便以后再代码里面查找到对应的控件

-->

<?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" 
android:background="#5f00"    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="用户名:" />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:hint="请输入用户名" >
            <requestFocus />
        </EditText>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:layout_weight="1"
            android:text="密码:" />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:layout_weight="2"
            android:hint="请输入用户名" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登录:" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="重置" />
    </LinearLayout>
</LinearLayout>

原文链接:http://www.apkbus.com/blog-690496-59542.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP