krystox wrote:Hi,
I have one XML layout file which defines a view, but I want to include it into another view as a portion. That view is also defined in XML. What is the syntax to include external files in the layout file? Anyone knows about it?
Thanks!
i haven't found a way to include a XML in another XML directly, so i create a ViewWrapper class that you can use as follows: (replace org.XXXX to your android package)
Using xml Syntax Highlighting
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res/org.XXXX"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <org.XXXX.ViewWrapper android:layout_width="fill_parent"
- android:layout_height="wrap_content" app:wrapLayout="@layout/text" />
- </LinearLayout>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
and the res/layout/text.xml is simply as follows:
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="UTF-8"?>
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:text="TEXT" android:layout_width="fill_parent"
- android:layout_height="fill_parent" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
if you want to use this ViewWrapper class, it only needs two files:
the res/values/attrs.xml: (defines the attribute app:wrapLayout in the ViewWrapper class)
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <declare-styleable name="ViewWrapper">
- <attr name="wrapLayout" />
- </declare-styleable>
- </resources>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
and the ViewWrapper.java:
Using java Syntax Highlighting
- package org.XXXX;
- import java.util.Map;
- import android.app.Activity;
- import android.content.Context;
- import android.util.AttributeSet;
- import android.view.View;
- import android.view.ViewInflate;
- import android.widget.FrameLayout;
- public class ViewWrapper extends FrameLayout {
- public ViewWrapper(Context context) {
- this(context, null, null);
- }
- public ViewWrapper(Context context, AttributeSet attrs, Map inflateParams) {
- super(context, attrs, inflateParams);
- android.content.Resources.StyledAttributes a = context
- .obtainStyledAttributes(attrs, R.styleable.ViewWrapper);
- int id = a.getResourceID(R.styleable.ViewWrapper_wrapLayout, -1);
- if (id > 0) {
- setView(id);
- }
- a.recycle();
- }
- public View setView(int resId) {
- ViewInflate vi = getContext() instanceof Activity ? ((Activity) getContext())
- .getViewInflate()
- : ViewInflate.from(getContext());
- View v = vi.inflate(resId, this, null);
- return v;
- }
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
that's it.
anyproblem, mailto: mmin18 [at] gmail
regards





always same error