Android 布局學習之——LinearLayout屬性baselineAligned的作用及baseline


    相信大家對LinearLayout已經相當熟悉,但你們是否了解它的屬性baselineAligned呢?

    Android官方文檔是這么描述的:

    

     那到底這個屬性是做什么用的呢?

         baselineAligned:基准線對齊。

     首先要解釋什么是基准線,這個在中文中不常見,但在以字母為書寫語言的其他國家非常常見。

    

      如上圖所示,紅線就是基線(baseline),是不是很熟悉,這不就是我們經常寫英文的四條線中的第三條嗎。

    

     那baselineAligned是做什么用的呢?根據官方文檔,baselineAligned默認設置為true,當設置為false時,

      布局文件和它的子組件的基准線不對齊。

      讓我們通過一個例子來看看效果怎樣的。

     

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="wrap_content"
 5     android:baselineAligned="false"
 6     android:orientation="horizontal">
 7 
 8     <TextView
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:layout_marginRight="5dip"
12         android:text="TextView:p" />
13     <TextView 
14         android:layout_width="wrap_content"
15         android:layout_height="wrap_content"
16         android:layout_marginRight="5dip"
17         android:textSize="30sp"
18         android:text="LargeTextView:p"
19         />
20 </LinearLayout>

 這是將baselineAligned值設置為false時,也就是不對齊。看看運行效果:

 

  把baselineAligned值改為true。

 

  看,差別明顯,這樣就很好的理解了baselineAligned的作用了。其實,這個並不難,但我覺得不管難不難,只要不明白,就應該多思考,想想為什么。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM