Android布局

来源:互联网 发布:迈卡威体测数据 编辑:程序博客网 时间:2024/05/29 08:15

1、布局中的位置属性设置

android:layout_centerInParent   居中布局
    android:layout_centerVertical    水平居中布局
    android:layout_alignParentBottom  居于容器内底部
    android:layout_above       居于指定View的上方
    android:layout_below       居于指定View的下方
    android:layout_toRightOf      在指定View的右边
    android:layout_toLeftOf        在指定View的左边
    android:layout_alignTop      与指定View的Top一致
    android:layout_centerHorizontal  垂直居中布局
    android:layout_alignParentTop    居于容器内顶部
    android:layout_alignParentLeft    居于容器内左边
android:layout_alignParentRight    居于容器内右边

2、实现布局

<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">                <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">                    <Button android:id="@+id/help" android:background="@drawable/main_button_left_under_bg" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />                    <LinearLayout android:gravity="center" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true">                        <ImageView android:background="@drawable/recommend" android:layout_width="wrap_content" android:layout_height="wrap_content" />                        <TextView android:textColor="@color/main_button_text_color" android:id="@+id/mp_text_help" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="推荐" />                    </LinearLayout>                </RelativeLayout>                <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">                    <Button android:id="@+id/setting" android:background="@drawable/main_button_right_under_bg" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" />                    <LinearLayout android:gravity="center" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true">                        <ImageView android:background="@drawable/tool" android:layout_width="wrap_content" android:layout_height="wrap_content" />                        <TextView android:textColor="@color/main_button_text_color" android:id="@+id/mp_text_setting" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="设置" />                    </LinearLayout>                </RelativeLayout></LinearLayout>





原创粉丝点击