2022-02-18 Android 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"
-
android:background="@color/purple_200">
-
-
-
<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="108元"
-
android:textSize="20sp"
-
android:gravity="center"
-
android:layout_marginTop="23dp"
-
/>
-
<!-- 在这个LinearLayout下,不指定orientation就默认horizontal -->
-
<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: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: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>
二、单个控件靠右
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
xmlns:tools="http://schemas.android.com/tools"
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:background="@color/purple_200"
-
tools:context=".ArrivedReport">
-
-
<RelativeLayout
-
android:id="@ id/background"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent">
-
-
<ImageView
-
android:id="@ id/backgroundphoto"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent" />
-
-
<LinearLayout
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:id="@ id/name_ground"
-
android:layout_marginTop="93dp"
-
android:layout_marginLeft="44dp"
-
android:layout_marginRight="44dp"
-
android:gravity="right"
-
android:orientation="horizontal">
-
<TextView
-
android:id="@ id/name"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:textSize="18dp"
-
android:text="黄静玲"
-
android:textColor="@color/black" />
-
</LinearLayout>
-
-
<LinearLayout
-
android:orientation="horizontal"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:id="@ id/time_ground"
-
android:layout_below="@ id/name_ground"
-
android:layout_marginTop="3dp"
-
android:layout_marginLeft="44dp"
-
android:layout_marginRight="44dp"
-
android:gravity="right">
-
<TextView
-
android:id="@ id/time"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:textSize="18dp"
-
android:textColor="@color/black"
-
android:text="2022-02-14 16:58" />
-
</LinearLayout>
-
<LinearLayout
-
android:orientation="horizontal"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:layout_below="@ id/time_ground"
-
android:id="@ id/address_ground"
-
android:layout_marginTop="44dp"
-
android:layout_marginLeft="44dp"
-
android:layout_marginRight="44dp"
-
android:gravity="center">
-
-
<TextView
-
android:id="@ id/address"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:textSize="23dp"
-
android:textColor="@color/black"
-
android:textStyle="bold"
-
android:text="天涯海角" />
-
</LinearLayout>
-
-
<TextView
-
android:id="@ id/test_time"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_below="@ id/address_ground"
-
android:layout_marginLeft="63dp"
-
android:layout_marginTop="370dp"
-
android:textSize="14dp"
-
android:textColor="@color/white"
-
android:text="2022-02-14 04:41" />
-
</RelativeLayout>
-
</LinearLayout>
三、效果三
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:background="@color/purple_200"
-
android:orientation="horizontal" >
-
-
<TextView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="左边1" />
-
-
<TextView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="左边2" />
-
<!-- 将TextView包在另一个LinearLayout中
-
注意android:layout_width和android:gravity这两个属性
-
-->
-
<LinearLayout
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:gravity="right" >
-
-
<TextView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_marginRight="10dp"
-
android:text="右边" />
-
</LinearLayout>
-
-
</LinearLayout>
四、参考文章
Android布局控件-LinearLayout详解 - 简书
Android学习——LinearLayout布局实现居中、左对齐、右对齐 - 最咸的鱼 - 博客园
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhficgkg
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
excel下划线不显示怎么办
PHP中文网 06-23 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
photoshop蒙版画笔没反应怎么办
PHP中文网 06-24