Android 开发之布局细节对比:Gravity相关

来源:互联网 发布:三权分立司法知乎 编辑:程序博客网 时间:2024/06/06 23:21

好吧,其实本不必写这篇文章,我打算接下来去写源码方面的。之所以写这个,主要是搜了一下网上已有的博客,都是一堆对属性的描述,我只想说,你们能不能上个图啊。

<?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">    <Button        android:text="第一个文本"        android:textSize="20sp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"/>    <Button        android:text="第二个文本"        android:textSize="20sp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center_horizontal"/>    <Button        android:text="第三个文本"        android:textSize="20sp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="fill_horizontal"/>    <Button        android:text="第四个文本"        android:textSize="20sp"        android:layout_width="200dp"        android:layout_height="50dp"        android:gravity="right"/>    <Button        android:text="第五个文本"        android:textSize="20sp"        android:layout_width="200dp"        android:layout_height="50dp"        android:layout_gravity="right"/>    <Button        android:text="第六个文本"        android:textSize="20sp"        android:layout_width="200dp"        android:layout_height="50dp"        android:gravity="right"        android:layout_gravity="right"/>    <Button        android:text="第七个文本"        android:textSize="20sp"        android:layout_width="200dp"        android:layout_height="80dp"        android:gravity="right|bottom"/>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical">        <Button            android:text="第八个文本"            android:textSize="20sp"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center"/>    </LinearLayout></LinearLayout>

未开启RTL时:

这里写图片描述

开启RTL时:

这里写图片描述

关于RTL可以看这个:Android 开发之布局细节对比:RTL模式

有一个小Demo,托管到GitHub上了,布局相关的博客代码都放到这一个工程下面了,欢迎大家Star啊。

GitHub AndroidLayout

2 0
原创粉丝点击