LZ利用的Include方式嵌入布局 , 其实都是一样的 。
你可以简单的理解为用include 就是把你那个search_shipments_layout.xml文件的布局代码直接替换过来。你在原有的布局文件怎么写布局代码 ,你在include的那个xml里面就怎么写。 

解决方案 »

  1.   

    图片地址:http://dl.javaeye.com/upload/picture/pic/55375/bcfb0e5a-dc73-32b6-a07a-23911725fb57.pnginclude 我是理解的。
    “你在原有的布局文件怎么写布局代码 ,你在include的那个xml里面就怎么写。 ”我明不明白的是怎么写布局代码,能给个例子不?我试着加入android:gravity="center",让“创新源于模仿!”这几个字在屏幕中间显示,但是不起作用,代码如下:<!--上面省略-->
    <LinearLayout android:id="@+id/shipments"
                              android:layout_width="fill_parent"
                              android:layout_height="fill_parent" android:gravity="center">
                    <include android:id="@+id/include_search_shipments" layout="@layout/search_shipments_layout"/>
    </LinearLayout>
    <!--下面省略-->
      

  2.   

    <LinearLayout android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:orientation = "vertical"
       android:background="@drawable/musicback">
       <!-- 嵌入搜索版块 -->
         <include layout = "@layout/search">
       </include>
    </LinearLayout><?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:background = "@drawable/search_background"
      android:layout_marginTop = "10dip"
      android:layout_marginLeft = "10dip"
      android:orientation="horizontal"
      android:layout_width="300dip"
      android:layout_height="60dip">
      
        <EditText android:id = "@+id/edit"
         android:text = "Music Search"
         android:layout_marginTop = "7dip"
       android:layout_marginLeft = "10dip"
       android:layout_height = "wrap_content"
       android:layout_width = "210dip" />
         <ImageButton android:id = "@+id/button"
          android:src = "@drawable/search"
          android:layout_marginTop = "6dip"
          android:layout_marginLeft = "10dip"
          android:layout_toRightOf = "@id/edit"
          android:layout_width = "wrap_content"
          android:layout_height = "wrap_content" /> 
         
    </RelativeLayout>这是我实际用到的一个XML布局 ,单独取了一部分include的代码出来, 后面的那个相对布局 , 就是单独做一个搜索小版块的 ,它在原有的布局中 , 就是置顶放置。
      

  3.   

    被include的search_shipments_layout.xml代码片段如下:<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center" android:layout_marginTop="10dip">
            <!---中间全都省略,全是一些ImageButton--->
    </LinearLayout> android:layout_marginTop="10dip" 在 tabhost里面好像是不起作用的。android:gravity="center"是起作用的。还是不能置顶啊????
      

  4.   

    属性android:gravity 设置它包含控件在此容器的位置
    属性android:layout_gravity 设置此容器在包含它的容器中的位置!
      

  5.   

    LS的回答不是我想要的答案,我的问题是,TabHost 其中的一个tab的布局,用include引入另一个布局文件,我想控制这个include的布局文件在这个tab里面的布局,比如让他在这个tab的屏幕最上方居中显示。
      

  6.   

    include 设置好高度就行了,关键是上面的ui高度适中就行了;
    我现在的问题是 要是其他tab也调用了 include里面的元素,如Button; 为什么在其他tab中 点击该BUtton 确不起作用呢?