请在下面找到我的布局&其结果;我需要文字'短信'以对齐文字'标题'的底线(请在代码和快照下方找到)。会很高兴,如果有人可以给我方向在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>
这是结果
这就是我需要
当字体大小不同时,不解决OP的问题。 – javajon 2015-01-13 17:37:00
其实它确实如此。当我意外地发现这一点时,我感到非常惊讶。现在我正在理解如何。 – 2016-04-18 19:28:27
我知道这是非常古老的,但我会在这里留下,因为我认为这很有帮助,LinearLayouts有一个名为“baselineAligned”(默认开启)的属性,它完全按照它的名称暗示:基于它们的视图基线(几乎每个TextView子类),除非它们具有重力,这就是为什么OP的布局无法正确工作。查看更多这里:https://possiblemobile.com/2013/10/shifty-baseline-alignment/ – 2017-05-23 22:06:11