0

最後のボタンが画面の下部に固定されるようにボタンをリストしたいとします。これについてはどうすればよいでしょうか。私の理解では、 LinearLayout はボタンの「リスト」を提供しますが、上部に固定されます。一方、RelativeLayout では一番下に固定できますが、すべての要素は次の要素への参照を持つ必要があり、XML ファイルは逆順になります (参照が有効になるため)。

これにどのようにアプローチすればよいですか?

編集:申し訳ありませんが、これは私が探しているものとほぼ同じです-

スクリーンショット

4

2 に答える 2

2

重み1のLinearLayoutを追加して、残りのスペースをすべて占有し、ボタンのリストをアクティビティの下部に押してみてください。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/widget32"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
    android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<Button
    android:id="@+id/widget33"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />
</LinearLayout>

サンプルXMLは、LinearLayoutによってアクティビティの下部にプッシュされる単一のボタン用です。ルートレイアウトも線形です。

于 2012-04-04T17:05:40.913 に答える
1

私はあなたの質問を正確に理解するのに苦労しています。しかし、私はあなたが欲しいのは画面の下部に固定されているボタンの水平方向のリストだと思いますか?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <!-- put your other views in here -->

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

        <Button
            android:id="@+id/button_cancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="cancel" />

        <Button
            android:id="@+id/button_ok"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="ok" />
    </LinearLayout>
</LinearLayout>
于 2012-04-04T17:06:41.070 に答える