3

I've created a custom view XML layout resource MyView.xml. Can I refer to MyView by the XML layout file inside a second XML layout such as main.xml? If so, how?

(To be clear, I'm not looking for replies that explain how to inflate views from within my Java code, or that explain introducing Java classes in XML layout resources with <com.MyDomain.App.MyView ...> unless this helps here or to clarify that I have no other option.)

1 Answer 1

3

If your XML file is like /res/layout/MyView.xml you can refer to in main.xml with

<?xml version=”1.0” encoding=”utf-8”?>

...

<include layout="@layout/MyView.xml" />

...

Sign up to request clarification or add additional context in comments.

3 Comments

And later use it with <MyView ...> as usual?
What do you mean exactly? Anyway <include> will include your predefined layout(s) as is from MyView.xml directly in main.xml after that no need to call or refer to any layout(s) you put in main.xml
Oh - I see, thanks. I'd misunderstood that <include> might appear at the top of the XML layout, like in header files. That's not the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.