将文本视图的基线与两种不同的布局对齐

时间:2013-05-21 08:45:01

标签: android android-layout relativelayout textview

我想将两个不同TextViews中的两个RelativeLayouts的基线对齐。以下是我正在使用的代码:

        <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right">

            <TextView 
                android:id="@+id/tv_city_a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="City"/>

        </RelativeLayout>

         <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

             <TextView 
                 android:id="@+id/tv_city_b"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_alignBottom="@id/tv_city"
                 android:background="@drawable/txt_field_white"/>

        </RelativeLayout>

我想将tv_city_a的基线与tv_city_b对齐,但上述代码无效。

注意:由于设计要求,我需要将TextView放在两个不同的RelativeLayout中。我不能把它们放在一起。

修改以下是我得到的输出: enter image description here

1 个答案:

答案 0 :(得分:0)

您无法将视图的基线与不同的父级链接起来。您唯一的选择是将它们加入1 RelativeLayout或通过提供正确的填充,边距,父对齐等使它们对齐。

编辑:错误的输出正在进行,因为您在第二个RelativeLayout中有android:paddingTop="5dp"

相关问题