您的位置:首页 > 其它

使用inlcude把一个布局插入到另一个布局中去

2014-05-26 15:34 162 查看
这个用法还是相当有用的,除了可以分工明确之外,也可以防止布局文件过大。

actvity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >
  <include 
      android:id="@+id/my_img_layout"
      layout="@layout/img_layout"
      />
	<include 
	    android:id="@+id/my_text_layout"
	    layout="@layout/text_layout"
	    />
</LinearLayout>


img_layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        />
     <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/news_small_default"
        />

</LinearLayout>


text_layout:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="hello,you"
        />

</merge>
效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐