我想知道如何使用RelativeLayout将视图放在两个其他视图之间(或视图和父级边缘之间).
例如,如果我有以下…
如何使用RelativeLayout在ImageView和屏幕底部之间垂直居中按钮?
我正在寻找一个解决方案,其中…
>按钮不会以任何方式拉伸
>没有嵌套的布局
而且我试图在XML布局(不以编程方式)中执行此操作.
解决方法
您可以使用以下内容:
<RelativeLayout
android:layout_below="@id/theImageView"
android:align_parentBottom="true"
android:layout_width="match_parent"
android:layout_height="200dp" >
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="onClickButton"
android:textSize="20sp"
android:text="Go"/>
</RelativeLayout>