LinearLayoutでbuttonを水平垂直中央に設定

2380 ワード

全部で2層のlinearlayoutがネストされています.最外層linearlayoutは内部垂直配列を設定し、その後、第2層linearlayoutは水平中央、内部水平配列を設定します.レイヤ2 linearlayoutの幅をwrap_に設定content、高さmatch_parentは、幅が設定されたbuttonの幅であると考えられ、高さは親レイアウトの高さでなければなりません.そうしないと、水平中心の効果は設定できません.
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_below="@+id/title_bar"
        android:orientation="vertical"
        android:background="#aaaaaa">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_gravity="center_horizontal">
            <Button
                android:id="@+id/person_photo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:text=" "/>
        LinearLayout>
    LinearLayout>