android:orientation="vertical"表示该布局下的元素垂直排列;

在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一个LinearLayout布局。

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="合计"
android:textSize="20sp"
android:gravity="center"
/> <TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1619元"
android:textSize="20sp"
android:gravity="center"
android:layout_marginTop="23dp"
/> <LinearLayout
android:layout_width="fill_parent" //在这个LinearLayout下,不指定orientation就默认horizontal
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="总里程:"
/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="266.86公里"
android:id="@+id/textView3"
/>
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="运费:"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="@color/colorAccent"
android:text="1639元"
/>
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="起步价(含5公里):"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="1571元"
/>
</LinearLayout> </LinearLayout>

实现效果如下:

Android学习——LinearLayout布局实现居中、左对齐、右对齐的更多相关文章

  1. Android学习----五大布局

    1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...

  2. Python3基础 str ljust-rjust-center 左、右对齐 居中

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  3. Android学习5—布局简介

    Android界面的布局主要有四种,分别为RelativeLayout.LinearLayout.TableLayout.FrameLayout,接下来分别介绍这些布局如何使用(为了简单起见,接下来的 ...

  4. android 学习 之 布局(上)

    学习安卓布局前,先了解三个属性值: 1.fill_parent: 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间 2.match_parent: And ...

  5. Android:LinearLayout布局中Layout_weight的深刻理解

    首先看一下LinearLayout布局中Layout_weight属性的作用:它是用来分配属于空间的一个属性,你可以设置他的权重.很多人不知道剩余空间是个什么概念,下面我先来说说剩余空间. 看下面代码 ...

  6. Word论文写作如何实现公式居中、编号右对齐

    第一步:插入表格 在公式所在行居中插入一行三列的表格,具体操作为: a.设置行居中,快捷键Ctrl+E: b.插入->表格->3×1的表格: 2 第二步:修改表格属性 新插入的表格三列等宽 ...

  7. android 学习 之 布局(下)LinearLayout,RelativeLayout,TableLayout,FrameLayout

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  8. 15.Android中LinearLayout布局一些小记录

    在App中,我们经常看到布局中会有分割线,直接上代码: <?xml version="1.0" encoding="utf-8"?> <Lin ...

  9. android 学习Layout布局的使用

    android 常用布局 LinearLayout(线性布局) 线性的 垂直的 水平的RelativeLaytout(相对布局) 最灵活的TableLayout(表格布局) 使用GridView代替A ...

随机推荐

  1. Python 函数(一)

      定义一个函数 函数的第一行语句可以选择性地使用文档字符串—用于存放函数说明. 函数内容以冒号起始,并且缩进. return [表达式] 结束函数,选择性地返回一个值给调用方.不带表达式的retur ...

  2. 前端将图片二进制流显示在html端

    工作中碰到的问题,在处理接口返回的验证码图片时,由于返回的是encode编码代码,在js端获取到数据之后,通过函数encodeURI()来进行解码,之后可以通过在src中设置来实现图片显示:

  3. Unity3D项目

    Input.mousePosition //鼠标点击的位置 0 左键  1右键  2滚轮 Input.GetMouseButton(0) //当鼠标左键处于按下状态的时候返回True Input.Ge ...

  4. Hua Wei 机试题目四---2014

    一.计算亮灯的个数 描述:一条长廊里依次装有n(1≤n≤65535)盏电灯,从头到尾编号1.2.3.…n-1.n.每盏电灯由一个拉线开关控制.开始,电灯全部关着. 有n个学生从长廊穿过.第一个学生把号 ...

  5. Windows下Java JDK安装和环境变量配置

    [Java攻城狮学习路线](http://www.cnblogs.com/apollospotatolikett/p/8665123.html 1.JDK下载 下载地址:http://www.orac ...

  6. PHP中的类函数和类对象

    1.class_exists()函数接受表示类的字符串,检查并返回布尔值.如果类存在,返回true,否则返回false: echo class_exists('Computer'); 2.get_cl ...

  7. HDU 1203 I NEED A OFFER!【01背包】

    解题思路:攒下的钱n相当于包的容量,然后是m个学校的申请费用,申请费用相当于每一个物品的消耗,得到offer的概率相当于每一个物品的价值. 因为要求的是至少得到一份0ffer的概率的最大概率,可以转化 ...

  8. dp入门—数塔

    在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?  已经告诉你了,这是个DP的题 ...

  9. 路飞学城Python-Day38(第四模块思维导图)

  10. 初见UDP_Server

    from socket import *ip_prot = ('192.168.55.1',8080)buffer_size = 1024udp_sever = socket(AF_INET,SOCK ...