0

ほとんどの画面が自分の GameView (View から派生したカスタム ビュー) でいっぱいになるようなゲームを作成しようとしています。

次に、画面の下部にメッセージなどを表示する領域が必要です。以下では、問題を説明するためにそこにボタンを配置しようとしています。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">

    <my.GameView 
        android:id="@+id/gameview" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" />

    <Button 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Action1" />

</LinearLayout>

これを実行すると、ボタンは表示されません。ボタンを GameView の前に移動すると、画面上部のボタンで機能します。上記のように、GameView は何らかの方法ですべての画面を取得しています。また、GameView に 1 の layout_weight を指定し、ボタンに 0 を指定しようとしました (逆も同様)。

GameView に onMeasure のものを実装する必要がありますか (まだ理解できませんでした)、それとも何か不足していますか?

4

2 に答える 2

2

GameView のサイズが画面と同じくらい大きい場合、Button は表示されません。これは、「wrap_content」を使用して、GameView に LinearLayout を必要なだけ取得する許可を与えるためです。

次のようにしてみてください。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<Button
    android:id="+@id/myButton"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"/>
<my.GameView 
    android:id="@+id/gameview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_above="@id/myButton"/>
</RelativeLayout>

お役に立てれば

于 2010-08-05T08:55:02.727 に答える
1

LinearLayout では、1 の layout_weight を GameView に与えるだけで、ボタンに重みを追加しないでください。それはうまくいくはずです。

それでもうまくいかない場合は、GameView の layout_height にも 0px を使用します。

<my.GameView 
    android:id="@+id/gameview" 
    android:layout_width="fill_parent" 
    android:layout_height="0px" 
    android:layout_weight="1"/>
于 2010-08-05T11:29:51.493 に答える