Lee*_*eem 8 android android-widget android-manifest android-emulator android-layout
如果我有一个名为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>
Run Code Online (Sandbox Code Playgroud)
有没有办法将上面的bottom.xml布局嵌入到其他布局中,而不是在几个布局文件中重复编写相同的代码(当其他布局的部分包含与bottom.xml相同的布局时)?
例如,如果我的admin.xml的布局还含有看起来一模一样的布局的一部分bottom.xml,如何只嵌入bottom.xml内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>
Run Code Online (Sandbox Code Playgroud)
如果在Android中无法做到这一点,可能是什么方法?
---------- -----------更新
像@xevincent建议的那样,我可以通过use 标签重用bottom.xml<include>,
但是如何更改已恢复布局中元素的ID?
例如,insdie bottom.xml,我想改变的ID <editText android:id="@+id/name">来 <editText android:id="@+id/other_name">时,我重用bottom.xml在其他布局,如何更改ID布局?
| 归档时间: |
|
| 查看次数: |
12598 次 |
| 最近记录: |