Android Api Demos登顶之路(六十三)Content-->Resources Smallest Width

这个demo演示 的主要是布局文件的技巧。
本例的基本思路是:
1.创建一个布局文件activity_row
该布局中只是定义了两个文本框,通过layout_weight属性,设置两个TextView平均分配屏幕的宽度。
需要注意的是这里使用了Merge节点。该节点可以使被include引用的布局在被嵌入父级结构中后可以很好的将它所包含的子集融合到父级结构中,而不会出现冗余的节点。

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <TextView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Default width #1"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:background="#800000ff"/>
        <TextView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Default width #2"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:background="#800000ff"/>
    </LinearLayout>

</merge>

2.activity_coluns.xml。在该布局中定义了两个均分屏幕剩余高度的FrameLayut。
并在该FrameLayout使用include引入了上面设置的布局

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <FrameLayout 
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="4dp"
            android:background="#8000ff00">
            <include layout="@layout/activity_row"/>
        </FrameLayout>
        <FrameLayout 
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="4dp"
            android:background="#8000ff00">
            <include layout="@layout/activity_row"/>
        </FrameLayout>
    </LinearLayout>


</merge>

3.定义主布局,activity_main,只是定义了一个TextView尔后将剩余的界面都归属了一个Framelayout.并在FrameLayout当中引入了activity_coluns.xml。这个布局

<LinearLayout 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:orientation="vertical" 
    android:padding="4dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/info" />
    <FrameLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@android:drawable/gallery_thumb">
        <include layout="@layout/activity_colums"/>
    </FrameLayout>

</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值