简体   繁体   中英

Android View View XML Programmatically

I'm trying to debug a view that I'm creating programmatically. I'd like to be able to see what the exact XML is of the view after it's created.

Really I'd like to be be able to do something like Log.d(TAG,view.toString())

And get an output like this:

<?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>

Is there anyway I can programmatically see what the xml is of a view?

There is nothing built in for that. You would have to write your own View -hierarchy-to-XML code or see if somebody has a library for that.

Or, use Android Studio's layout inspector .

Or, use uiautomatorviewer .

Or, use Stetho .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM