Android LinearLayout及TextView的布局方式

来源:互联网 发布:新点预算软件 编辑:程序博客网 时间:2024/04/29 00:52

1、LinearLayout(线性布局)

android:orientation="vertical"垂直线性布局,"horizontal"水平线性布局

android:gravity="top"(buttom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal)控制布局中控件的对齐方式。如果是没有子控件的控件设置此属性,表示其内容的对齐方式,比如说TextView里面文字的对齐方式;若是有子控件的控件设置此属性,则表示其子控件的对齐方式,gravity如果需要设置多个属性值,需要使用“|”进行组合

android:gravity 与 android:layout_gravity的区别
android:gravity是指定本元素的子元素相对它的对齐方式。
android:layout_gravity是指定本元素相对它的父元素的对齐方式。


2、TextView

 TextView的drawableLeft、drawableRight和drawableTop是一个常用、好用的属性,可以在文本的上下左右放置一个图片,而不使用更加复杂布局就能达到。

如图所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:drawableBottom="@drawable/ic_launcher"        android:drawableLeft="@drawable/ic_launcher"        android:drawablePadding="30dp"        android:drawableRight="@drawable/ic_launcher"        android:drawableTop="@drawable/ic_launcher"        android:gravity="center_vertical"        android:text="啦啦啦啦啦啦啦啦" /></LinearLayout>




0 0