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. ZYQAssetPickerController的使用,不错的图片选择

    import UIKit class ViewController: UIViewController,ZYQAssetPickerControllerDelegate,UIImagePickerCo ...

  2. adplus 抓取dump

    工具所在路径   C:\Program Files\Windows Kits\10\Debuggers\x64 cmd窗口切换目录倒adplus所在路径下,输入抓取命令.adplus -hang -p ...

  3. Java基础——类和对象的初始化过程

    本节把类和对象的初始化所涉及到的所有代码块阐述一边. 示例代码: public class Demo { private static String name; private String age; ...

  4. ViewPager滑动到最后一页再向左滑动进入主界面

    在OnPageChangeListener中的onPageScrolled方法里判断 @Override public void onPageScrolled(int arg0, float arg1 ...

  5. (转)GPT磁盘与MBR磁盘区别

    摘要:   Windows 2008磁盘管理器中,在磁盘标签处右击鼠标,随磁盘属性的不同会出现“转换到动态磁盘”,“转换到基本磁盘”“转换成GPT磁盘”,“转换成MBR磁盘”等选项,在此做简单介绍.部 ...

  6. 。net内存优化

    1.尽量减少和避免不必要的对象 2.优化算法和数据结构 3.采用非托管代码或者模块编写数据处理逻辑 4.NET应用程序的内存一定程度上受垃圾回收的影响.并指出,一些数据结构如List,系统会分配多余的 ...

  7. ABBYY FineReader双十一优惠享不停,战绩如何?

    随着双十一的火热来袭,购物达人也是不吝啬囊中票子,各种姿势剁手齐全,立誓过后吃土半月,双十一的好与不好?自己也是门清,反正真真的是促进消费了! 就ABBYYFineReader而言,此次的双十一力度就 ...

  8. [转] hadoop MapReduce实例解析-非常不错,讲解清晰

    来源:http://blog.csdn.net/liuxiaochen123/article/details/8786715?utm_source=tuicool 2013-04-11 10:15 4 ...

  9. Pyhton学习——Day33

    #并发式编程# 操作系统是一个用来协调.管理和控制计算机硬件和软件资源的系统程序,它位于硬件和应用程序之间.# (程序是运行在系统上的具有某种功能的软件,比如说浏览器,音乐播放器等.)# 操作系统的内 ...

  10. BZOJ 3697/3127 采药人的路径 (点分治)

    题目大意: 从前有一棵无向树,树上边权均为$0$或$1$,有一个采药人,他认为如果一条路径上边权为$0$和$1$的边数量相等,那么这条路径阴阳平衡.他想寻找一条合法的采药路径,保证阴阳平衡.然后他发现 ...