现在的位置: 首页 > 综合 > 正文

Relative 实现平分,替换layout_weight 嵌套使用

2017年11月05日 ⁄ 综合 ⁄ 共 1229字 ⁄ 字号 评论关闭

效果如上,布局如下:

<?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:background="#ffffff" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="200dip"
        android:background="#000000" >

        <LinearLayout
            android:id="@+id/photo"
            android:layout_width="100dip"
            android:layout_height="200dip"
            android:background="#ff0000"
            android:orientation="vertical" >
        </LinearLayout>

        <View
            android:id="@+id/divide"
            android:layout_width="0dip"
            android:layout_height="0dip"
            android:layout_centerVertical="true"
            android:background="#ffffff" />

        <Button
            android:layout_width="0dip"
            android:layout_height="0dip"
            android:layout_above="@id/divide"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@id/photo"
            android:background="#00ff00"
            android:text="Top" />

        <Button
            android:layout_width="0dip"
            android:layout_height="0dip"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_below="@id/divide"
            android:layout_toRightOf="@id/photo"
            android:background="#0000ff"
            android:text="Bottom" />
    </RelativeLayout>

</RelativeLayout>

抱歉!评论已关闭.