【问题标题】:Align base line of textviews in two different layouts在两种不同的布局中对齐文本视图的基线
【发布时间】:2013-05-15 23:08:50
【问题描述】:

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

        <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 中。我不能把它们放在一起。

编辑以下是我得到的输出:

【问题讨论】:

  • 你能发布你的输出或完整的布局
  • 你可以将两个相对布局放在一些线性布局中

标签: android android-layout android-relativelayout textview


【解决方案1】:

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

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

【讨论】:

  • 所以它不可能实现我想要的。还有其他方法吗?
  • @VinodMaurya 您可以尝试测量 TextView A 的位置,然后相应地放置 TextView B...
猜你喜欢
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 2016-10-27
  • 2012-07-05
  • 1970-01-01
  • 1970-01-01
  • 2011-01-07
相关资源
最近更新 更多