Android视图以编程方式查看XML
我正在尝试调试一个以编程方式创建的视图。我希望能够在创建视图后看到视图的确切XML 真的,我希望能够像Android视图以编程方式查看XML,android,xml,Android,Xml,我正在尝试调试一个以编程方式创建的视图。我希望能够在创建视图后看到视图的确切XML 真的,我希望能够像Log.d(TAG,view.toString()) 并得到如下输出: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/activity_main" xmlns:android="http://schemas.android.com/apk/res/android"
Log.d(TAG,view.toString())
并得到如下输出:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="sampleapp.example.com.tr221test.MainActivity">
<Button android:id="@+id/surveyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Survey!"/>
</RelativeLayout>
我是否可以通过编程方式查看视图中的xml是什么?没有为此内置任何内容。您必须将自己的
视图
-层次结构编写为XML代码,或者查看是否有人为此提供了库
或者,使用
或
或者,.这是为了调试目的吗?确实如此。我敢肯定,我已经打乱了一些视图的添加顺序——试图以编程方式重新创建现有视图。有关相应工具的链接,请参阅Commonware的答案。Layout inspector是一个不错的新工具!我认为没有任何简单的方法可以将其复制为XML?:)@汤姆哈蒙德:我不知道。Stetho的输出是XML,但更多的是试图让布局看起来是Chrome开发工具要处理的有效HTML。