LinearLayout中的属性baselineAligned的使用

来源:互联网 发布:亚信数据全球总部 编辑:程序博客网 时间:2024/05/17 02:18

Android线性布局中的属性主要的就是控制浮动方向的orientation,其他的就是辅助浮动显示的,其中有一个属性控制基线,也就是baselineAligned,让我有点迷惑,下边通过例子讲解下这个属性的使用。

1.首先这个基线主要是对可以显示文字的View,如TextView,Button等控件的

2.这个baseline指的是这个UI控件的baseline--文字距UI控件顶部的偏移量

3.LinearLayout控件默认有属性android:baselineAligned为true,如果LinearLayout的orientation为horizontal的话,其中的文字默认是文字对齐的

        下边举个例子看下,效果和代码如下:

 

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:baselineAlignedChildIndex="3"  
  6.     android:orientation="horizontal" >  
  7.   
  8.     <TextView  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_marginRight="3dip"  
  12.         android:text="String1" />  
  13.   
  14.     <LinearLayout  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content"  
  17.         android:baselineAlignedChildIndex="1"  
  18.         android:orientation="vertical" >  
  19.   
  20.         <ImageView  
  21.             android:layout_width="wrap_content"  
  22.             android:layout_height="wrap_content"  
  23.             android:src="@android:drawable/arrow_up_float" />  
  24.   
  25.         <TextView  
  26.             android:layout_width="wrap_content"  
  27.             android:layout_height="wrap_content"  
  28.             android:layout_marginRight="5dip"  
  29.             android:text="String2" />  
  30.   
  31.         <ImageView  
  32.             android:layout_width="wrap_content"  
  33.             android:layout_height="wrap_content"  
  34.             android:src="@android:drawable/arrow_down_float" />  
  35.     </LinearLayout>  
  36.   
  37.     <LinearLayout  
  38.         android:layout_width="wrap_content"  
  39.         android:layout_height="wrap_content"  
  40.         android:baselineAligned="true"  
  41.         android:baselineAlignedChildIndex="2"  
  42.         android:orientation="vertical" >  
  43.   
  44.         <ImageView  
  45.             android:layout_width="wrap_content"  
  46.             android:layout_height="wrap_content"  
  47.             android:src="@android:drawable/arrow_up_float" />  
  48.   
  49.         <ImageView  
  50.             android:layout_width="wrap_content"  
  51.             android:layout_height="wrap_content"  
  52.             android:src="@android:drawable/arrow_down_float" />  
  53.   
  54.         <TextView  
  55.             android:layout_width="wrap_content"  
  56.             android:layout_height="wrap_content"  
  57.             android:layout_marginRight="5dip"  
  58.             android:text="String3" />  
  59.     </LinearLayout>  
  60.   
  61.     <TextView  
  62.         android:layout_width="wrap_content"  
  63.         android:layout_height="wrap_content"  
  64.         android:text="String4"  
  65.         android:textSize="60sp" />  
  66.   
  67. </LinearLayout>  

 其中的baselineAlignedChildIndex指的是其中的第几个子控件按照baseline对齐的。

转载地址:http://txlong-onz.iteye.com/blog/1961170

0 0