4

フレーム レイアウトに 2 つのボタンがあり、それらを画面の下部に並べて配置したいと考えています。

を使用android:layout_gravity="bottom"すると、互いにオーバーラップします。Relativelayout で問題はありませんが、relativelayout はサポートしていませんandroid:layout_gravity="bottom"

私の XML レイアウト ファイル

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

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scanit"
        android:layout_gravity="bottom"
        android:text="Button 1" />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/inf"
        android:layout_gravity="bottom"
        android:text="Button 2" />
</FrameLayout>
4

5 に答える 5

11

そのために以下のレイアウトコードを使用すると、役立つ場合があります。

<?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" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/mLlayoutBottomButtons" >
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/mLlayoutBottomButtons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button2" />
    </LinearLayout>

</RelativeLayout>
于 2012-06-30T07:05:04.607 に答える
4

使用android:gravity="bottom"relative layout使用android:layout_alignParentBottom="true"

于 2012-06-30T06:55:51.457 に答える
2

私の理解では、上の他のウィジェットが余分なスペースを埋めるように指定すれば、画面の下部を占めるレイアウト/ウィジェットのセットを使用できます。これは、レイアウトの重みパラメーターを使用して行われます。ここでは、2 つのボタンを必要に応じて向きを合わせて線形レイアウトに配置します。次に、上記の残りのウィジェットは、重み = 1 の別のレイアウトにあります。重み 1 のレイアウトは成長し、ボタンをカバーしません。

これをより詳細に示すブログ投稿

これは以下のようになります画面はこちら

于 2013-07-04T17:43:09.963 に答える
1

これを試して

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


<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Button1" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button1" 
    android:text="Button2" />

</RelativeLayout>
于 2012-06-30T06:59:53.443 に答える