004.线性布局管理器

1.      布局管理器线性两种,垂直线性布局管理器,水平线性布局管理器,边缘外的组件不会显示

2.      主要2个属性 orientation 和 gravity

这两个是LinearLayout属性,写在LinerLayout标记内

3.      还有子属性(就是写在LinearLayout内的子组件的属性)

layout_weight:组件占父容器剩余空间的比例

4.      gravity属性,若要设置多个,则要用|分开

5.mipmap的x越多,图片越小,而且(好像)会根据手机分辨率变化


实例实现微信登录界面

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp"
    tools:context=".MainActivity">

    <!--以后布局管理器中还是都用一下padding吧,感觉这样写出来会比较好-->

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dp"
        android:hint="qq/微信号/Email"
        android:drawableLeft="@mipmap/zhanghao"/>

    <!--编辑框组件 edittext
        layout_width=""
        match_parent(宽度)与父容器相同
        wrap_content(宽度)包裹其自身内容

        记得每一个(线性布局管理器)子组件都要加paddingbottom 大约20dp
        hint提示文本,(不是实体内容,切记)

        drawableLeft设置左边的图标

        -->



    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dp"
        android:hint="密码"
        android:drawableLeft="@mipmap/mima"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textColor="#ffffff"
        android:background="#ff009688"/>

    <!--text属性为 设置显示文字
        textColor 设置文字颜色
        background-->


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录遇到问题?"
        android:layout_gravity="center"
        android:paddingTop="20dp"/>

    <!--android:layout_gravity="center" 使子组件居中显示-->

    <!--现在界面上方是蓝色的,不太好看,想把它改成蓝色,
    我们可以修改他的主题,在AndroidManifest中修改
    android:theme="@style/AppTheme">
    改为android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
    改了主题后,虽然预览和设计中不会有变化,但运行时确实会有变化-->

    <!--还有图片资源别作死的用中文名,不然运行时会出错-->
</LinearLayout>

猜你喜欢

转载自blog.csdn.net/qq_38309980/article/details/80881369