gpt4 book ai didi

java - XML 布局到 Java 代码转换器

转载 作者:数据小太阳 更新时间:2023-10-29 02:49:53 25 4
gpt4 key购买 nike

我知道在 Android 中,所有 XML 布局文件在编译时都会转换为 Java 代码。有什么方法可以访问那些 java 代码(java 中的布局)?

或者如果没有办法,我能找到任何转换器吗?

--

例如:

XML 布局:

<TextView
android:layout_width="50px">
</TextView>

Java代码:

TextView textview = new TextView();
textview.setWidth(50);

--

如您所见,这只是一个简单的示例,但是布局通常要长得多。逐行转换需要很长时间。

有什么建议吗?

最佳答案

Is there any way to have access to those java codes (layout in java)?

没有这样的“代码”。欢迎您考察the source to LayoutInflater ,如您所见,它看起来与您的设想大不相同。

is there any converters I can find?

对于 Stack Overflow,请求场外资源被认为是题外话。郑重声明,我什么都不知道,如果有人花时间研究它,我会感到震惊。

It would take a very long time to convert it line by line.

那就先用Java写吧。或者,直接使用 XML 布局资源。

I'm working on a project where it will be much easier to work with Java code rather than XML

虽然我不能排除这种可能性,但它会相当令人惊讶。

关于java - XML 布局到 Java 代码转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23639823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com