Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

android - What is the baseline in RelativeLayout?

What does "baseline" refer to when used in the context of a relative layout? Simple question, probably, but the documentation and google offer no hints.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The term baseline comes from typography. It's the invisible line letters in text sit on.

For example, imagine you put two TextView elements next to each other. You give the second TextView a big padding (say 20dp). If you add layout_alignBaseline to the second element, the text will "scoot up" to align with the baseline of the first element. The text from both elements will appear as if they were written on the same invisible line.

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
  <TextView
      android:id="@+id/text1"
      android:text="aatlg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      />
  <TextView
      android:text="joof"
      android:background="#00ff00"
      android:padding="20dp"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_toRightOf="@id/text1"
      android:layout_alignBaseline="@id/text1"
      />
</RelativeLayout>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...