如何嵌入里面的另一个布局在我的情况? [英] How to embed one layout inside another in my case?

查看:122
本文介绍了如何嵌入里面的另一个布局在我的情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个名为布局的 bottom.xml

If I have a layout called bottom.xml,

bottom.xml:(只包含一个TextView和编辑文本视图)

bottom.xml:(simply contain a textview and edit text view)

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical"
     >
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal" 
            android:text="@string/username"

        />

        <EditText 
            android:id="@+id/name"

            android:layout_width="120dip"
            android:layout_height="50dip"
            android:layout_gravity="center_horizontal"     
        />
 </LinearLayout>

有没有办法为嵌入上面的 bottom.xml 里面的其他布局,而不是反复编写相同的code布局一些布局文件(当其他的布局有一个包含相同的布局bottom.xml的一部分)?

Is there any way to embed the above bottom.xml layout inside other layouts instead of repeatly writing the same code in several layout files (when other layouts have a part which contains the same layout as bottom.xml)?

例如,如果我的 admin.xml的的布局中也含有它看起来完全一样的 bottom.xml ,如何只嵌入 bottom.xml 内部> <> admin.xml的的> 而不是写的同样的code再?

For example, if my admin.xml layout also contain part of the layout which looks exactly the same as bottom.xml, how to just embed the bottom.xml inside admin.xml instead of writing the same code again?

admin.xml的:

admin.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     >
     ...
     ...
        <!--How to embed bottom.xml here-->
     ...
 </LinearLayout>

如果没有办法做到这一点在Android中,这可能是解决办法?

If there is no way to do it in Android, what could be the workaround??

---------- -----------更新

像@xevincent建议,我可以重复使用的<​​strong>的 bottom.xml 通过使用&LT;包括&GT; 标签,

Like @xevincent suggested, I can reuse the bottom.xml by use <include> tag,

但如何改变resued布局中的元素的ID?

But How to change the id of the elements inside the resued layout?

例如,insdie的 bottom.xml ,我想改变&LT的ID; EDITTEXT机器人:ID =@ + ID /名称&GT; &LT; EDITTEXT机器人:ID =@ + ID / OTHER_NAME&GT; 当我重新使用的 bottom.xml 在其他版面布局,如何更改ID?

For example, insdie bottom.xml, I would like to change the id of <editText android:id="@+id/name"> to <editText android:id="@+id/other_name"> when I reuse the bottom.xml layout in other layout, how to change the id ?

推荐答案

请参阅本文档<一个href="http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html">reusing布局的。

这篇关于如何嵌入里面的另一个布局在我的情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆