是否有一个Android工具来找到一个正在运行的应用程序布局的名字吗? [英] Is there an Android tool to find the name of a layout for a running app?

查看:256
本文介绍了是否有一个Android工具来找到一个正在运行的应用程序布局的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在最近聘请了维持非常大型程序(只有两个活动,大约一百片段,几百布局)。此外,大多数的布局(图像和文本),以及该命令的内容的该布局出现动态通过公司的Web API测定

I have been recently hired to maintain a very large program (only two Activities, about a hundred Fragments, and several hundred layouts). Furthermore, most of the content of the layouts (images and text) as well as the order that the layouts appear is dynamically determined via the company's Web API.

不幸的是没有文档。没有地图,虚无缥缈。该公司聘请了第三方做长这个程序,他们甚至使用的是Android程序员面前。而code的质量差最好(即使变量名是混乱和矛盾的)。

Unfortunately there is no documentation. No map, nada. The company hired a 3rd party to make this app long before they even had Android programmers. And the quality of the code is poor at best (even variable names are confusing and contradictory).

因此​​,我花了大约70% - 90%的时间用简单的搜索布局和code只是改变按钮的背景

Consequently, I spend about 70% - 90% of my time simply searching for layouts and code just to change the background of Button.

是否有一个工具,一个可以运行(Android Studio中的调试器吧?),可以以某种方式吐当前显示的布局文件的名称?

Is there a tool that one can run (perhaps in Android Studio's debugger?) that can somehow spit the names of the layout files that are currently displayed?

我的上司经常这样说,改变从黑这样的背景纹理浅灰色。而且我想:变化是微不足道的,但是的找到的XML文件可能需要一个小时。

My superiors often say something like, "Change that background texture from black to light gray." And I'm thinking: the change is trivial, but finding the xml file could take an hour.

推荐答案

在Android设备监控,有一个按钮,你可以点击名为转储视图层次的用户界面的Automator。

Hierarchy Viewer tool

In the Android Device Monitor, there is a button you can click on called "Dump View Hierarchy for UI Automator".

这将在设备监视器打开UI层次观众,你可以用它来看看你的每一个观点的资源ID。

This will open a UI Hierarchy viewer in the Device Monitor, which you can use to see the resource IDs of each of your views.

虽然这实际上不会给你充气XML文件的名称,也可能是非常有用的。如果你是幸运的,你甚至可以用grep的资源ID来缩小为看哪个XML文件的搜索。

While this does not actually give you the name of the inflated XML file, it could be very useful. If you are lucky, you can even grep for the resource IDs to narrow down the search for which XML files to look at.

如果你将鼠标悬停在浏览器窗口的标题,它会告诉你的路径它创造实际的XML文件。这是找到所有的资源ID在一个地方的方式。

And if you hover over the title of the viewer window, it will show you the path to the actual XML file that it created. This is a way to find all the resource IDs in one place.

在对案件层次查看一些更多的信息可以帮助:

Some more info on Hierarchy Viewer in case it helps:

  • How to get to Hierarchy View while running the app on my device connected to android studio
  • or straight from the Android Developer docs

层次浏览器允许你调试和优化用户
  接口。它提供了布局的视图的视觉重新presentation
  层次结构(布局视图)和显示的放大督察
  (像素完美的视图)。

The Hierarchy Viewer allows you to debug and optimize your user interface. It provides a visual representation of the layout's View hierarchy (the Layout View) and a magnified inspector of the display (the Pixel Perfect View).

下面是一个包含一些有趣的博客文章 - 它可以拦截所有视图通胀自定义布局吹气:


Create a custom Layout Inflater in code

Here's a blog post that contains something interesting - a custom layout inflater that intercepts all view inflation:

它可能会使用该样本code拦截膨胀通话,接收的资源ID的XML文件的:

It may be possible to use that sample code to intercept the inflate calls, and receive the resource ID of the XML file:

  • LayoutInflator.inflate() on Android Developer docs

在这一点上,你需要打开的资源ID 的成有用的名称。从这个问题引用(如何从资源ID ),你可以使用:

At this point, you will need to turn the resource id into a useful name. Quoting from this question (How to get Resource Name from Resource id), you can use:

getResources().getResourceEntryName(int resid);

添加一些记录,这可能会给你每一个XML文件,因为它是被夸大了。

Add some logging and this may give you each XML file as it is being inflated.

这可能是相当不错的方式来记录您的整个项目。

This could be quite a nice way to document your entire project.

这篇关于是否有一个Android工具来找到一个正在运行的应用程序布局的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆