vui lòng tìm bên dưới bố cục của tôi & kết quả của nó; Tôi cần văn bản 'Tin nhắn văn bản' để căn chỉnh trên đường cơ sở của văn bản 'Tiêu đề' (Vui lòng tìm bên dưới mã và ảnh chụp nhanh). Sẽ rất vui nếu ai đó có thể cho tôi hướngCăn chỉnh đường cơ sở của hai chế độ xem văn bản trong Android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0"
android:baselineAligned="true"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:background="@color/custom_orange"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Header"
android:textSize="25sp"
android:id="@+id/title"
android:gravity="center"
android:background="@color/custom_red"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Text message"
android:textSize="10sp"
android:id="@+id/language"
android:gravity="center"
android:background="@color/custom_green"/>
</LinearLayout>
</LinearLayout>
Đây là kết quả
Đây là những gì tôi cần
Không giải quyết câu hỏi của OP khi phông chữ có kích thước khác nhau. – javajon
Thực tế là có. Tôi đã rất ngạc nhiên khi tôi vô tình tìm ra điều này. Bây giờ tôi đang cố gắng hiểu CÁCH. –
Tôi biết điều này thực sự cũ, nhưng tôi sẽ chỉ để lại điều này vì tôi nghĩ nó hữu ích, LinearLayouts có một thuộc tính được gọi là "baselineAligned" (được bật theo mặc định), thực hiện chính xác tên của nó: Điều chỉnh các khung nhìn dựa trên đường cơ sở (khá nhiều mọi lớp con TextView) trừ khi chúng có trọng lực, đó là lý do tại sao bố cục của OP không hoạt động chính xác. Xem thêm tại đây: https://possiblemobile.com/2013/10/shifty-baseline-alignment/ –