0

おそらく空きスペースを予約することにより、将来の動的なアクティビティにもかかわらず、レイアウトで次のコード化されたボタンを所定の位置に保持する方法を見つけようとしています。メニュー ボタンと他の 3 つのボタンの間には、動的に作成された事前選択に基づいてランダムなサイズとランダムな量のボタンのグリッドがあります。しかし、ボタンの数やサイズに関係なく、main.xml で設計されたこれら 4 つのボタンを適切な位置に維持したいと考えています。

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

    <Button
        android:id="@+id/menu"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="MENU" />

これは懸念される領域です。メニュー ボタン (上) が常に画面の上部に配置され、ステップ、一時停止、シミュレート ボタン (下) が常に画面の一番下に配置されるようにしたいと考えています。

    <Button
        android:id="@+id/step"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/grid"
        android:layout_centerHorizontal="true"
        android:text="STEP" />

    <Button
        android:id="@+id/pause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/grid"
        android:layout_toLeftOf="@id/step"
        android:text="PAUSE" />

    <Button
        android:id="@+id/sim"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/grid"
        android:layout_toRightOf="@id/step"
        android:text="SIMULATE" />

    <SeekBar
        android:id="@+id/speed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/sim"
        android:layout_alignParentLeft="true"/>

</RelativeLayout>

私は自分の質問の解決策を見つけました。他の 3 つのボタンのメニュー ボタンの後に "android:layout_alignParentBottom="true" を使用する必要がありましたが、必要に応じて動的に追加されたボタンをその間に配置できるようになりました。

このウェブサイトでは、自分の質問に答えることはできません。

4

1 に答える 1

1

RelativeLayout を LinearLayout にします。すべてのボタンに「android:layout_weight="0"」を指定します。次に、目的の空きスペースに、android:layout_height="0" と "android:layout_weight="1"" を持つビューを追加します。あなたの質問を正しく理解していれば、それでうまくいくはずです。

于 2012-06-15T05:04:51.493 に答える