当前位置: 首页 > news >正文

【Android】界面布局-线性布局-例子

线性布局(LinearLayout)是一种重要的界面布局中,也是经常使用到的一种界面布局

在线性布局中,所有的子元素都按照垂直或水平的顺序在界面上排列

如果垂直排列,则每行仅包含一个界面元素

➢如果水平排列,则每列仅包含一个界面元素

代码示例 

用户名-请输入用户名-确认-取消

1.水平实现

<?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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="用户名" />

    <EditText
        android:id="@+id/editTextText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:minHeight="48dp"
        android:text="请输入用户名" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="确认" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="取消" />

</LinearLayout>

结果演示 :

2.垂直实现

仅需修改参数为vertical

android:orientation="vertical"

结果演示 : 

Tips

直接拖动,创建所需组件

上面创建的就是输入框EditText:

  • 功能:允许用户输入文本,常用于表单数据收集。
  • 关键属性
    • android:inputType:定义输入类型(如 textnumberemail)。
    • android:hint:设置输入框的提示文本(用户输入时消失)。

http://www.dtcms.com/a/111314.html

相关文章:

  • 【Cursor】设置语言
  • css炫酷的3D水波纹文字效果实现详解
  • 数字化三维实训室:无穿戴动作捕捉技术如何赋能体育与舞蹈
  • 木马学习记录
  • 影响RTOS实时性的因素有哪些?
  • 容器文件系统
  • 【python中级】关于Cython 的源代码pyx的说明
  • 面试算法高频02-树
  • Elasticsearch使用示例
  • 第五讲(下)| string类的模拟实现
  • vector的介绍与代码演示
  • 27信号和槽_自定义信号(2)
  • 语文常识推翻百年“R完备、封闭”论
  • 神马系统8.5搭建过程,附源码数据库
  • 电子商务类型
  • 15使用按钮实现helloworld(2)
  • 智能安卓手机清理工具,深度优化内存卡顿解决方案
  • OCR迁移
  • 蓝桥杯2024年第十五届省赛真题-R 格式
  • 安卓手机的重复文件清理工具
  • MySQL学习笔记——MySQL下载安装配置(一)
  • xpath定位
  • 康拓展开补充:逆康拓展开
  • 强化中小学人工智能教育:塑造未来社会的科技基石
  • Linux C++编译及g++使用操作
  • Python集合(五)
  • PostgreSQL 删除数据库
  • Vanna:用检索增强生成(RAG)技术革新自然语言转SQL
  • 深入解析大型应用架构:以dify为例进行分析
  • goto在Java中的用法