iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android基础知识及线性布局的示例分析
  • 390
分享到

Android基础知识及线性布局的示例分析

2023-06-26 05:06:25 390人浏览 八月长安
摘要

这篇文章主要介绍Android基础知识及线性布局的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1.常见控件的基本属性android:id="@+id/button1":【设置控件id】a

这篇文章主要介绍Android基础知识及线性布局的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

    1.常见控件的基本属性

    android:id="@+id/button1":【设置控件id】

    android:layout_width【设置控件宽度】/android:layout_height【设置控件高度】

    wrap_content【控件的大小由内部决定】

    match_parent【控件的大小与父控件保持一致】

    android:text=" ":【设置组件文本】

    android:textColor=" ":【设置字体颜色】

    android:layout_marginLeft:【当前布局与父布局左边缘的距离】

    android:layout_marginRight:【当前布局与父布局右边缘的距离】

    android:layout_marginTop:【当前布局与父布局顶部边缘的距离】

    android:layout_marginBottom:【当前布局与父布局底部边缘的距离】

    android:gravity :【view里面的内容在这个view中的位置】

    android:layout_gravity :【这个view相对于它父view的位置】

    gravity在线性布局中不起任何作用,layout_gravity在线性布局中起作用;
    2、 当我们使用 android:orientation=“vertical” 时, android:layout_gravity只有水平方向的设置才起作用,
    垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的;
    3、当 我们使用android:orientation=“horizontal” 时, android:layout_gravity只有垂直方向的设置才起作用,
    水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。

    1.1控件的可见性

    该属性有三种状态值:Gone、visible、invisible。

    gone 与invisible的区别是:
    gone 表示控件不可见,也不会占任何的位置,也不会有任何响应。
    而invisible表示控件虽然不可见,但是会占据它的宽高位置。

    例子:

    <LinearLayout      android:id="@+id/linearLayout"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:orientation="horizontal"      app:layout_constraintEnd_toEndOf="parent"      app:layout_constraintStart_toStartOf="parent"      app:layout_constraintTop_toTopOf="parent">      <Button          android:id="@+id/button1"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight="1"          android:text="button1">      </Button>      <Button          android:id="@+id/button2"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight="1"          android:visibility="invisible"      //invisible表示控件虽然不可见,但是会占据它的宽高位置。          android:text="button2">      </Button>      <Button          android:id="@+id/button3"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight="1"          android:text="button3"></Button>  </LinearLayout>

    效果如图:

    Android基础知识及线性布局的示例分析

    例子:

    <LinearLayout      android:id="@+id/linearLayout"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:orientation="horizontal"      app:layout_constraintEnd_toEndOf="parent"      app:layout_constraintStart_toStartOf="parent"      app:layout_constraintTop_toTopOf="parent">      <Button          android:id="@+id/button1"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight="1"          android:text="button1">      </Button>      <Button          android:id="@+id/button2"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight="1"          android:visibility="gone"     //gone 表示控件不可见,也不会占任何的位置,也不会有任何响应。          android:text="button2">      </Button>      <Button          android:id="@+id/button3"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight="1"          android:text="button3">      </Button>  </LinearLayout>

    效果如图:

    Android基础知识及线性布局的示例分析

    1.2控件的外边距

    学习html的都会知道CSS里的盒模式有个外边距和内边距。
    外边距可以设置视图距离父视图上下左右的距离。
    内边距可以设置视图内部内容距离自己边框上下左右的距离。
    Android 的控件布局其实也用的是这个盒模式。

    如果距离父视图上下左右的外边距相同,可以这么设置:

    android:layout_margin="10dp"

    我们也可以单独的设置某个外边距:

    android:layout_marginTop="10dp"android:layout_marginBottom="10dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"

    1.3控件的内边距

    统一设置上下左右内边距:

    android:padding="5dp"

    各自设置内边距:

    android:paddingTop="5dp"android:paddingBottom="5dp"android:paddingLeft="5dp"android:paddingRight="5dp"

    2.线性布局(Linear Layout)

    LinearLayout 核心属性:
    (1) android:orientation:两个属性值:“vertical” 垂直 “horizontal”水平
    (2) android:layout_weight 将父控件的剩余空间按照设置的权重比例再分配

    2.1示例:

    Android基础知识及线性布局的示例分析

    <LinearLayout        android:id="@+id/linearLayout"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent">        <Button            android:id="@+id/button1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="button1">        </Button>        <Button            android:id="@+id/button2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="button2">        </Button>        <Button            android:id="@+id/button3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="button3">        </Button>    </LinearLayout>

    2.2微信界面实战

    Android基础知识及线性布局的示例分析

    <?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:orientation="vertical"    android:layout_height="match_parent"    tools:context=".MainActivity">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="×"        android:textSize="50dp"        android:layout_marginLeft="5dp"/>    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="20dp"        android:layout_marginTop="5dp"        android:text="微信号/QQ/邮箱登录"        android:textColor="@color/black"        android:textSize="30dp"/><!--第一个框架-->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="30dp">        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:layout_marginTop="6dp"            android:orientation="horizontal">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="25dp"                android:text="账号"                android:textColor="@color/black"                android:textSize="25dp" />        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0">            <EditText                android:layout_width="wrap_content"                android:layout_height="match_parent"                android:text="请填写微信号/QQ号/邮箱                  "/>        </LinearLayout>    </LinearLayout><!--第二个框架-->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="45dp"        android:layout_marginTop="10dp"        android:orientation="horizontal">        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="25dp"                android:text="密码"                android:textColor="@color/black"                android:textSize="25dp" />        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0">        <EditText            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="请填写密码                                          "/>        </LinearLayout>    </LinearLayout>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="用手机号登录"            android:layout_marginTop="20dp"            android:layout_marginLeft="25dp"            android:textSize="20dp"            android:textColor="@color/purple_500"/>    <Button        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="登录"        android:textSize="30dp"        android:layout_marginTop="30dp"        /><!--    第三个框架-->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="150dp"        android:orientation="horizontal">        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="2">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="找回密码"                android:layout_marginLeft="80dp"                android:textColor="@color/purple_500"                android:textSize="15dp" />        </LinearLayout>        <LinearLayout            android:layout_width="122dp"            android:layout_height="wrap_content"            android:layout_weight="7">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="紧急冻结"                android:layout_marginLeft="40dp"                android:textColor="@color/purple_500"                android:textSize="15dp" />        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="70">            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="微信安全中心"                android:textColor="@color/purple_500"/>        </LinearLayout>    </LinearLayout></LinearLayout>

    以上是“Android基础知识及线性布局的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网精选频道!

    --结束END--

    本文标题: Android基础知识及线性布局的示例分析

    本文链接: https://www.lsjlt.com/news/307067.html(转载时请注明来源链接)

    有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

    本篇文章演示代码以及资料文档资料下载

    下载Word文档到电脑,方便收藏和打印~

    下载Word文档
    猜你喜欢
    • Android基础知识及线性布局的示例分析
      这篇文章主要介绍Android基础知识及线性布局的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1.常见控件的基本属性android:id="@+id/button1":【设置控件id】a...
      99+
      2023-06-26
    • Android基础知识及线性布局介绍
      目录1.常见控件的基本属性1.1控件的可见性1.2控件的外边距1.3控件的内边距2.线性布局(Linear Layout)2.1示例:2.2微信界面实战3.总结1.常见控件的基本属性...
      99+
      2024-04-02
    • AngularJS基础知识的示例分析
      这篇文章主要介绍了AngularJS基础知识的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。指令AngularJS 指令是扩展的 H...
      99+
      2024-04-02
    • HTTP报文及ajax基础知识的示例分析
      小编给大家分享一下HTTP报文及ajax基础知识的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!HTTP报文客户端传递给...
      99+
      2024-04-02
    • HTML基础知识点的示例分析
      这篇文章将为大家详细讲解有关HTML基础知识点的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。   一、HTML是谁发明的   1990年Tim Berner...
      99+
      2024-04-02
    • java中基础知识的示例分析
      这篇文章主要为大家展示了“java中基础知识的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“java中基础知识的示例分析”这篇文章吧。一.异常Java对异常的处理同Delphi一样,不是...
      99+
      2023-06-03
    • mysql中基础知识的示例分析
      这篇文章将为大家详细讲解有关mysql中基础知识的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。mysql架构一、网络连接层客户端连接器(Client Conne...
      99+
      2024-04-02
    • Python基础知识点的示例分析
      这篇文章给大家分享的是有关Python基础知识点的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。一、python中的标志符:给变量取的名字就是标志符区分大小写,MyName和myname是两个不同的标志符...
      99+
      2023-06-29
    • javascript中json基础知识的示例分析
      这篇文章将为大家详细讲解有关javascript中json基础知识的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。大致介绍JSON(JavaScript Obje...
      99+
      2024-04-02
    • HTML基础知识之DIV的示例分析
      小编给大家分享一下HTML基础知识之DIV的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧! 一、HTML 块元素 ...
      99+
      2024-04-02
    • Java中基础知识点的示例分析
      这篇文章主要为大家展示了“Java中基础知识点的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Java中基础知识点的示例分析”这篇文章吧。1、String类1.1两种对象实例化方式对于S...
      99+
      2023-06-20
    • Spring中bean基础知识的示例分析
      这篇文章主要为大家展示了“Spring中bean基础知识的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Spring中bean基础知识的示例分析”这篇文章吧。Bean:在Spring技术...
      99+
      2023-05-30
      spring bean
    • navicat for mysql基础知识的示例分析
      这篇文章主要介绍了navicat for mysql基础知识的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。一、数据库的操作新建数据库打开数据库右键或者双击就可以了。...
      99+
      2023-06-15
    • html基础图像知识的示例分析
      这篇文章将为大家详细讲解有关html基础图像知识的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。   要在页面上显示图像,你需要使用源属性(src)。src指&...
      99+
      2024-04-02
    • Python基础知识实例分析
      这篇文章主要介绍了Python基础知识实例分析的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python基础知识实例分析文章都会有所收获,下面我们一起来看看吧。在Python 语言中,对象是通过引用传递的。多元...
      99+
      2023-06-17
    • mysql数据库基础知识点的示例分析
      这篇文章将为大家详细讲解有关mysql数据库基础知识点的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。数据库一、 修改数据表添加一列:ALTERTABL...
      99+
      2024-04-02
    • Android 基础知识4-2.10 GridLayout(网格布局)详解
      一、GridLayout(网格布局)概述         GridLayout 布局是 Android 4.0 以后引入的新布局,和 TableLayout(表格布局) 有点类似,不过它功能更多,也更加好用,最大的特点是放置的组件自动占据网...
      99+
      2023-09-02
      android android studio 学习
    • CSS的布局基础知识点有哪些
      本篇内容介绍了“CSS的布局基础知识点有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!常见布局种类一列布局自上而下的,一般头部进行固定宽...
      99+
      2023-06-27
    • h5新特性及网页布局的示例分析
      这篇文章主要介绍了h5新特性及网页布局的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。HTML5 中的一些有趣的新特性:用于绘画的 ...
      99+
      2024-04-02
    • java局部变量表的基础知识点及实例
      说明 1、局部变量表也叫局部变量数组或本地变量表。定义为一个数组,主要用于存储方法参数和定义方法中的局部变量。这些数据类型包括各种基本数据类型、对象参考和returnAddress类...
      99+
      2024-04-02
    软考高级职称资格查询
    编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
    • 官方手机版

    • 微信公众号

    • 商务合作