I know that in Android all XML layout files are converted to Java code on compilation. Is there any way to have access to those java codes (layout in java)?
Or if there isn't a way, is there any converters I can find?
--
For example:
XML layout:
<TextView
android:layout_width="50px">
</TextView>
Java code:
TextView textview = new TextView();
textview.setWidth(50);
--
As you can see, this is just a simple example, however, layouts are usually much longer. It would take a very long time to convert it line by line.
Any suggestions?
Is there any way to have access to those java codes (layout in java)?
There are no such "codes". You are welcome to examine the source to LayoutInflater, which, as you will see, looks substantially different than what you envision.
is there any converters I can find?
Asking for off-site resources is considered off-topic for Stack Overflow. For the record, I am not aware of any, and I'd be stunned if somebody spent their time on it.
It would take a very long time to convert it line by line.
Then write it in Java in the first place. Or, use the XML layout resources directly.
I'm working on a project where it will be much easier to work with Java code rather than XML
While I cannot rule out this possibility, it would be rather surprising.
You can try this solution:
http://www.xmltojava.com/
For your example:
<TextView
android:layout_width="50px">
</TextView>
Will result in the following Java code:
TextView textView_706 = new TextView(this);
LayoutParams layout_420 = new LayoutParams();
layout_420.width = 50px;
textView_706.setLayoutParams(layout_420);
Obviously, the naming is a little problematic but it's a small refractor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With