0

次のようなレイアウトがあるとします。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <TextView
        android:id="@+id/greeting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello, world!" />

    <LinearLayout
        android:id="@+id/actions"
        style="?android:attr/buttonBarStyle"
        android:background="#dddddd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/button1"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Button1" />

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Button2" />

    </LinearLayout>
</RelativeLayout>

Eclipse でレンダリングすると、次のようになります。

ここに画像の説明を入力

ButtonBar の周りに余白があることに注意してください。残りのアクティビティに影響を与えずにこれを削除する方法はありますか? 属性を変更するとandroid:padding*、「Hello, world!」アクティビティの左側にぶつかります。

4

2 に答える 2

2

android:padding*を要素に移動greetingし、親レイアウトから削除します。次に、そのアイテムだけにパディングがありますが、ボタンバーにはパディングがありません。

後で追加の項目を追加する必要がある場合 (単一の ではなくTextView)、それらを新しいレイアウトでラップし、そのレイアウトにパディングを配置する必要があります。

于 2013-03-09T22:16:22.043 に答える
0

作成したレイアウトごとにandroid:paddingを設定します...親レイアウト内に配置された子には、それらのパディングが設定されます...代わりにlayout_marginを使用できます...

于 2013-03-09T22:34:09.723 に答える