首页 > 其他分享 >安卓布局常用代码介绍6——线性布局使用代码例子

安卓布局常用代码介绍6——线性布局使用代码例子

时间:2022-10-26 11:38:52浏览次数:87  
标签:layout 代码 布局 height content wrap 安卓 id android


效果如下:

安卓布局常用代码介绍6——线性布局使用代码例子_线性布局


设置思路:

先利用线性布局先垂直排列

第一行插入一个线性布局:水平排列,用比例排列;

第二行插入一个线性布局:垂直排列,用weight=1垂直;

中间这个线性布局就各种微调。

第三行插入一个线性布局:因为第二行的线性布局填充了界面,所以第三行到了最底下。然后用weight来均匀排列。

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">


<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="输入日期:"
android:textSize="18sp"/>

<EditText
android:id = "@+id/getyear"
android:textColor = "#999999"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="年份"

<EditText
android:id = "@+id/getmonth"
android:textColor = "#999999"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="月份"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"

<EditText
android:id = "@+id/getdate"
android:textColor = "#999999"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="日期"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">

<Button
android:id="@+id/btn_set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="设置"

<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:text="距考研仅剩"
android:textSize="24sp"
android:textColor="#000000"

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/time_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:text="100"
android:textSize="100sp"
android:background="#0000"
android:layout_marginTop="0dp"

<TextView
android:id="@+id/text_View_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:text="天"
android:textSize="24sp"
android:textColor="#000000"

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/days_target"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0000"
android:layout_marginLeft="100sp"
android:text="目标日:"
android:textSize="20sp"

<TextView
android:id="@+id/days_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#0000"
android:gravity="center"
android:text="2018-12-22"
android:textSize="20sp"

</LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/tip"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="贴士"
android:textSize="20sp"
android:background="#00000000"

<Button
android:id="@+id/main"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="首页"
android:textSize="20sp"

<Button
android:id="@+id/note"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="随笔"
android:textSize="20sp"
android:background="#00000000"

</LinearLayout>


</LinearLayout>


标签:layout,代码,布局,height,content,wrap,安卓,id,android
From: https://blog.51cto.com/u_15847108/5797518

相关文章

  • 安卓布局常用代码介绍5——使用布局的个人经验
    水平较差,仅供参考,欢迎指正一、距离单位使用的经验1.不要使用px;(因为总是冒黄色警告,手动滑稽);2.设置控件大小,距离时,使用pd单位;3.设置字体大小时,使用sp单位;二、使用布局的......
  • 安卓Material Desigh常用代码介绍1——MD的介绍。
    首先说明一点,这博客属于笔记的一种,所以缘由介绍什么的都省略了。前期就主要写写代码。想到啥写啥。深入的问题,等水平提高之后再说。对于MD,按照我的理解不完全分类可分为七部......
  • 安卓布局常用代码介绍1——相对布局篇
    安卓常用布局有五个,框架布局FrameLayout(也称帧布局)相对布局RelativeLayout绝对布局AbsoluteLayout线性布局LinearLayout表格布局TableLayout这五个布局在View......
  • 反编译安卓aar文件
    下载地址:https://varaneckas.com/jad/下载最新的符合自己系统的文件,解压之后包含jad.exe和Readme.txt文件将要反编译的aar包改成zip然后解压一下,再将解压后里面的classes......
  • 有什么推荐的开源erp代码?
    XBS(3UCSERP)是3UCS于2020年开始开源的面向制造型企业ERP系统,开源仓库在github.com(https://github.com/dspflash/3ucsERP)/sf.net(3ucsERP)/gitee(bizfree/三优ERP_3ucs)三个开......
  • 公司新入职一个中级 Java 开发,4 行代码写出了 3 个异常,我真的服了。。
    作者:l拉不拉米链接:https://juejin.cn/post/7031445206152577061一、前言Hello大家好,我是l拉不拉米,今天带来一个真实案例,让大家更深刻的理解空指针异常。公司刚入职了......
  • 什么是低代码(Low-Code)?
    低代码(Low-Code)就是应用新技术、新思想、新的软件架构、新的设计方法打造一个软件定制平台,来实现相对较低的代码编写而实现软件应用需求的目的,其目的就是要降低软件应用......
  • 前端面试题之手写代码篇
    前端面试题之手写代码篇:https://loveworld.blog.csdn.net/article/details/117464917?spm=1001.2101.3001.6650.7&utm_medium=distribute.pc_relevant.none-task-blog-2%7E......
  • 代码随想录训练营第十四天 | 二叉树
    今天是第十四天,除了二叉树的基本概念外,还有递归法的应用 144.二叉树的前序遍历classSolution{publicList<Integer>preorderTraversal(TreeNoderoot){......
  • 代码随想录day21 | 530.二叉搜索树的最小绝对差 501. 二叉搜索树中的众数 236. 二叉
    530.二叉搜索树的最小绝对差题目|文章思路二叉搜索树的特点是按照中序遍历从小到大进行排列,因此,按照中序遍历,逐个比较即可找到最小差值进行中序遍历,当前节点和前一个......