【发布时间】:2015-09-02 06:31:20
【问题描述】:
有点尴尬,但我在将一些视图对齐到 RelativeLayout 时遇到了一些基本问题。我的 XML 如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MyActivity">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/background"
android:scaleType="centerCrop"
android:src="@drawable/background"/>
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:id="@+id/imageview"
android:src="@drawable/text" />
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:enabled="false"
android:id="@+id/button"
android:background="@drawable/buttonxml"
android:layout_below="@+id/imageview"
android:layout_alignLeft="@id/imageview"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/coin"
android:src="@drawable/coin"
android:layout_below="@id/imageview"
android:layout_alignRight="@id/imageview"/>
</RelativeLayout>
我有一个居中的 ImageView (id/imageview),我想要两个视图在下方对齐 - 一个在左侧,一个在右侧。但是,对于上面的 xml,似乎两个较小的视图正在与 id/imageview 对齐,而没有考虑到它已经居中的事实:
在我将 id/imageview 居中之前,它看起来如下所示(请注意,较小的视图现在按预期对齐,尽管它们没有移动):
除了使用 LinearLayouts 集合之外还有什么想法吗?我觉得这很简单,可以用 RelativeLayout 来处理,我可能只是在做一些愚蠢的事情。提前致谢!
【问题讨论】:
标签: android android-layout alignment android-relativelayout