android – 如何在我的情况下将一个布局嵌入另一个布局?

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

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

<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布局嵌入到其他布局中,而不是在几个布局文件中重复编写相同的代码(当其他布局的部分包含与bottom.xml相同的布局时)?

例如,如果我的admin.xml布局还包含与bottom.xml完全相同的部分布局,那么如何在bottom.xml中嵌入bottom.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中无法做到这一点,可能是什么方法

———- ———–更新

像@xevincent建议的那样,我可以通过使用< include>来重用bottom.xml.标签,

但是如何更改已恢复布局中元素的ID?

例如,insdie bottom.xml,我想更改< editText android:id =“@ id / name”>的id. to< editText android:id =“@ id / other_name”>当我在其他布局中重用bottom.xml布局时,如何更改id?

解决方法

请参阅此文档 reusing layouts.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...