1

对此有很多不同的建议,但它们似乎都不适用于 layout:gravity 等(尽管我可能做错了)。

我希望在屏幕底部绘制我的按钮,而不是在屏幕顶部的默认位置绘制它们。我确信有一种简单的方法可以做到这一点。

目前,按钮绘制在顶部

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:game_view="http://schemas.android.com/apk/res/pap.crowslanding"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<FrameLayout
    android:id="@+id/flayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/button1"
    android:orientation="vertical" >

    <pap.crowslanding.GameView
        android:id="@+id/game_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        game_view:ballDiam="@dimen/ballDiam"
        game_view:cellWidth="@dimen/cellWidth"
        game_view:pixelHeight="@dimen/pixelHeight"
        game_view:pixelWidth="@dimen/pixelWidth" />

    <pap.crowslanding.MazeBall
        android:id="@+id/mazeball"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="invisible"
        game_view:ballDiam="@dimen/ballDiam"
        game_view:cellWidth="@dimen/cellWidth" />
</FrameLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_weight="1"
        android:text="@string/right" >
    </Button>

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/down" />
</LinearLayout>

4

2 回答 2

3

父容器是 a RelativeLayout,所以你只需要添加android:android:layout_alignParentBottom=true到你的LinearLayout并去掉那个layout_gravity属性。

于 2013-04-19T19:49:59.860 回答
0

您可以尝试以下方法:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:game_view="http://schemas.android.com/apk/res/pap.crowslanding"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<FrameLayout
    android:id="@+id/flayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/button1"
    android:orientation="vertical" >

    <pap.crowslanding.GameView
        android:id="@+id/game_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        game_view:ballDiam="@dimen/ballDiam"
        game_view:cellWidth="@dimen/cellWidth"
        game_view:pixelHeight="@dimen/pixelHeight"
        game_view:pixelWidth="@dimen/pixelWidth" />

    <pap.crowslanding.MazeBall
        android:id="@+id/mazeball"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="invisible"
        game_view:ballDiam="@dimen/ballDiam"
        game_view:cellWidth="@dimen/cellWidth" />
    </FrameLayout>
    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="@string/right" >
    </Button>

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="@string/down" />
</RelativeLayout> 

然后你需要调整你的按钮,使它们不在彼此之上(android:layout_toRightOf="@+id/button_name"android:layout_toLeftOf=...)。我不知道你想要左右哪个。你也应该使用match_parent而不是fill_parent. fill_parent在 API 8 中已弃用(我认为是 8,但我知道它已被弃用)。

于 2013-04-19T19:35:55.677 回答