我正在尝试使用RelativeLayout将按钮置于屏幕的右下角和左下角。我希望通过这种方式在不同尺寸的屏幕上保持相同的相对布局。目前,我的屏幕上的按钮会根据屏幕分辨率上下移动。例如320x480屏幕上的按钮位置比480x800更高。我想让两个尺寸的屏幕看起来相同。
我知道这是一个旧主题,但它出现在搜索结果的顶部,所以我想确认一下。
android:layout_alignParentBottom="true"
在RelativeLayout中对我有用。
例子:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:panel="http://schemas.android.com/apk/res/it.kronplatz"
android:id="@+id/MainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/ButtonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:baselineAligned="false" >
<ImageButton
android:id="@+id/locateMeButton"
android:layout_width="70px"
android:layout_height="70px"
android:layout_marginLeft="5px"
android:src="@drawable/me" >
</ImageButton>
<ImageButton
android:id="@+id/MapCenterButton"
android:layout_width="70px"
android:layout_height="70px"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5px"
android:src="@drawable/fadenkreuz_klein" />
<Button
android:id="@+id/MapNextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/androidmarker" >
</Button>
</RelativeLayout>
</RelativeLayout>
您是否正在使用android:layout_alignParent*?这应该可以使其靠近屏幕边缘,而不受屏幕大小的影响。
其中*为Bottom或Top或Left或Right
除了AedonEtLIRA所说的外,您还应确保RelativeLayout始终填充整个显示区域。也就是说,在视图层次结构中没有任何地方定义大小,而是使用match_parent。如果您然后使用AedonEtLIRA提供的布局定义,您应该会得到您想要的结果。