LZ利用的Include方式嵌入布局 , 其实都是一样的 。
你可以简单的理解为用include 就是把你那个search_shipments_layout.xml文件的布局代码直接替换过来。你在原有的布局文件怎么写布局代码 ,你在include的那个xml里面就怎么写。
你可以简单的理解为用include 就是把你那个search_shipments_layout.xml文件的布局代码直接替换过来。你在原有的布局文件怎么写布局代码 ,你在include的那个xml里面就怎么写。
调试欢乐多
“你在原有的布局文件怎么写布局代码 ,你在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>
<!--下面省略-->
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的代码出来, 后面的那个相对布局 , 就是单独做一个搜索小版块的 ,它在原有的布局中 , 就是置顶放置。
<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"是起作用的。还是不能置顶啊????
属性android:layout_gravity 设置此容器在包含它的容器中的位置!
我现在的问题是 要是其他tab也调用了 include里面的元素,如Button; 为什么在其他tab中 点击该BUtton 确不起作用呢?