【问题标题】:android - aligning siblings of different relative layoutsandroid - 对齐不同相对布局的兄弟姐妹
【发布时间】:2014-05-18 12:12:51
【问题描述】:

我想知道是否可以将不同相对布局的 2 个兄弟姐妹相互对齐。 例如,给定这个 XML:

<RelativeLayout>
  ..
  <RelativeLayout android:id="@+id/layout1" >
    ..
    <TextView android:id="@+id/text1 />
  </RelativeLayout>
  <RelativeLayout android:id="@+id/layout2" >
    ..
    <TextView android:id="@+id/text2 />
  </RelativeLayout>
</RelativeLayout>

我想将 text1 和 text2 相互对齐。可能吗?或者,还有其他方法可以实现这样的目标吗? 谢谢!!

【问题讨论】:

  • I would like to align text1 and text2 with each other. is it possible? alternately, is there some other way to achieve something like this? YES:将两个 TextView 对齐到父级的左侧,将它们的父级对齐到祖父级的左侧。如果两个 TextView 在同一个容器中会更好。
  • 好的,谢谢。我有一种感觉,这将是一个问题,但只是想确定一下。欢迎您写下您的评论作为答案,以便我接受:)
  • 好的,完成。也许它也对其他人有帮助! ;)

标签: android xml android-relativelayout


【解决方案1】:

I would like to align text1 and text2 with each other. is it possible?
简单地说,NO,不是。
因为控件位于不同的(“并行”)容器中,所以它们彼此不可见。

alternately, is there some other way to achieve something like this?
幸运的是,是的有:

TextViews 对齐到父级的左侧,它们的父级对齐祖父级的左侧。

不过,如果两个 TextView 在同一个容器中会更好。

【讨论】:

    猜你喜欢
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    相关资源
    最近更新 更多