android - 在 Android 中对齐两个 TextView 的基线

标签 android textview

请在下面找到我的布局及其结果;我需要文本“Text message”与文本“Header”的基线对齐(请在下面找到代码和快照)。如果有人能给我指导,我会很高兴

<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>

这是结果

enter image description here

这就是我想要的

enter image description here

最佳答案

使用RelativeLayout作为TextViews的容器并添加属性

android:layout_alignBaseline="@+id/title"

id/language TextView

关于android - 在 Android 中对齐两个 TextView 的基线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26822876/

相关文章:

java - 拦截带有继承的 Parcelable 时出现 ClassCastException

android - 包含长 TextView 时缺少线性布局背景

java - 我如何从 View 而不是 TextView 获取文本

Android Studio、Google Firebase、Google map

android - 单个系列和单个渲染器的多个颜色条

android - 显示键盘时如何向上移动整个布局?

ios - 在不关闭键盘的情况下显示具有 UITextField 的 UIAlertController

安卓 : Why onClick method is not working?

java - TextView 椭圆在 setText() 上消失

android - ParseException 未找到查询结果