开发者

Android: vertically stretching buttons

I have an application in which there are two buttons side-by-side at the bottom (in a TableLayout inside a RelativeLayout). This looks fine on small screens, but on larger screens there is an ugly black space left at the bot开发者_C百科tom. I want to expand the buttons vertically to fill the space, but can't work out how!

I've included the code below (with the contents of the RelativeLayout removed for simplicity; the below behaves in exactly the same way as the version with it)

<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent">
            <Button android:layout_width="wrap_content" android:id="@+id/Button01" android:text="@string/Button01" android:layout_weight="50" android:layout_height="fill_parent"></Button>
            <Button android:layout_width="wrap_content" android:id="@+id/Button02" android:text="@string/Button02" android:layout_weight="50" android:layout_height="fill_parent"></Button>
        </TableRow>
    </TableLayout>

</RelativeLayout>

Anyone have any idea how to stretch the buttons in the current layout, or a different layout that will allow me to do this more easily?

Thanks,


As your within a relative layout could you not use the property android:layout_alignParentBottom='true' and force the bottom edge of the buttons to align with the bottom edge of the layout? You could apply bottom margin to leave some gap.


After a little (lot) more experimentation, it turns out that I was approaching this the wrong way. By removing the TableLayout, and replacing it with a LinearLayout the fill_parent attribute for height started working as expected, and all is good.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜