Android miscellaneous-what is the baseline in relativelayout?

Source: Internet
Author: User

It seems simple and difficult to understand. In fact, this baseline is equivalent to the line below when writing text in the notebook. The example of baseline in relativelayout is as follows:

For example, add two adjacent textviews and a larger padding (such as 20dp) to the second textview. If layout_alignbaseline is added to the second textview, the text "world" in textview is in the same horizontal line as "hello" in the first textview, and the second textview control is moved up, it is like "hello" and "world" are on the same line. If layout_alignbaseline is not added, see the following for details.

<RelativeLayout 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" >    <TextView         android:id="@+id/text1"        android:text="hello"        android:background="#aa0000"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        />            <TextView            android:text="world"            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>

 

1: layout_alignbaseline not added

2: Add layout_alignbaseline, just like two lines of text Hello world written online.

3: Set the second textview to the layout_below attribute in the test verticals without adding layout_alignbaseline.

4. Set the second textview to the layout_below attribute and add layout_alignbaseline. As you can see, it overwrites the above control, but it is not vertically centered.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.