FrameLayout

在LinearLayout中如果在水平布局上的组件是两个,要想第二个在居中显示,就得靠FrameLayout这个布局,

比如有两个组件,第一个靠左边,是一个返回按钮,第二个是一个TextView在居中显示

代码如下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical" >
    <!-- 标题开始 -->
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/nav">

        <Button
            android:id="@+id/detiled_btback"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:background="@drawable/button20"
            android:text="@string/back"
            android:textColor="@color/white"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|center_vertical"
            android:text="@string/detail"
            android:textColor="@color/meetText"
            android:textSize="20sp"/>
    </FrameLayout>

</LinearLayout>

你可能感兴趣的:(android,布局)