Android学习——LinearLayout布局实现居中、左对齐、右对齐

时间:2023-01-29 10:20:36

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布局实现居中、左对齐、右对齐

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&mdash&semi;布局简介

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

  4. android 学习 之 布局(上)

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

  5. Android:LinearLayout布局中Layout&lowbar;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&period;Android中LinearLayout布局一些小记录

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

  9. android 学习Layout布局的使用

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

随机推荐

  1. Javascript中构造函数与new命令2

    典型的面向对象编程语言(比如C++和Java),存在"类"(class)这个概念.所谓"类"就是对象的模板,对象就是"类"的实例.但是,在J ...

  2. find xargs exec rm

    有时候比如我们删除上万行的文件种的几千行需要怎么做呢 如果配合find 和exec 因为exec有个内存溢出的可能所以一般都会有控制. 例如: find . -name *.log -exec rm ...

  3. SpringMVC 配置log4j

    log4j.properties相关 http://www.cnblogs.com/ITEagle/archive/2010/04/23/1718365.html http://www.cnblogs ...

  4. ecmall模板语法

    ECMall的模板解析语法介绍 用"{"开头,以"}"结尾就构成一个标签单元 在 2011年07月19日 那天写的     已经有 19105 次阅读了 感谢  ...

  5. When not to automate 什么时候不进行自动化

    The cornerstone of test automation is the premise that the expected application behavior is known. W ...

  6. 将html导出到excel或word

    本质是将html写成word或excel支持的html格式. 如何将html写成word或excel支持的格式? 只需打开计算机上任意一个word或excel文档,打开文件->另存为,选择文件类 ...

  7. 一。Hibernate 开发流程

    一.hibernate和mybatis都是orm产品1.orm:object-realation-mapping对象关系映射 二.开发步骤1.导入相关jar 包括hibernate和oracle的驱动 ...

  8. python decimal&period;quantize&lpar;&rpar;参数rounding的各参数解释与行为

    我最开始其实是由于疑惑ROUND_FLOOR和 ROUND_DOWN的表现区别才看了一波文档,但是感觉拉出一票以前没有留意过的东西. 贴一个decimal文档里面的解释: ROUND_CEILING ...

  9. C语言程序设计--指针基础

    指针 指针是一种特殊变量(存储内存地址).当然它本身也是占用内存的,所以会带来一个问题,那就是指针存在以下概念:指针的类型(int* 一个整型指针),指针指向的类型(int* p = 5, 说明指针p ...

  10. Java之集合&lpar;十四&rpar;Hashtable

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7426522.html 1.前言 HashTable这个类很奇特,其继承了Dictionary这个没有任何具体实现 ...