简体   繁体   English

在Eclipse中预览所有Android XML布局文件

[英]Preview all Android XML layout files in Eclipse

Is it possible to preview all Android XML layout files in Eclipse at once? 是否可以一次在Eclipse中预览所有Android XML布局文件?

(I do not think to preview one single layout in different screen resolution, theme or API!) (我不认为可以以不同的屏幕分辨率,主题或API预览单个布局!)

I have many similar dialog and sometimes I need to preview all layout to find one I need. 我有许多类似的对话框,有时我需要预览所有布局以找到所需的对话框。

Here's a self-contained activity that: 这是一个自包含的活动,该活动:

  1. Dynamically loads all layout id values 动态加载所有布局ID值
  2. Has a touch listener that will cycle through all layouts 有一个触摸监听器,可以循环浏览所有布局
  3. Shows the current layout name in a short Toast message 在简短的Toast消息中显示当前布局名称

REQUEST: 请求:
Would be great if someone can suggest a way to add the layout name programmatically to appear over the layout after the view updates. 如果有人可以建议一种在视图更新后以编程方式添加布局名称以显示在布局上方的方法,那就太好了。

public class MainActivity extends Activity 
{
    List<Integer> layoutIds = new ArrayList<Integer>();
    Map<Integer, String> layoutNameMap = new HashMap<Integer, String>();

    int curIdx = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        loadLayoutIds();

        showNext();   
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) 
    {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
            showNext();

        return true;
    }

    private void showNext()
    {
        if (curIdx >= layoutIds.size())
            curIdx = 0;

        int layoutId = (int) layoutIds.get(curIdx);

        setContentView(layoutId);

        String msg = layoutNameMap.get(layoutId);

        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();

        curIdx++;
    }

    private void loadLayoutIds()
    {
        try
        {
            Class<?> c = R.layout.class;
            Field[] fields = c.getDeclaredFields();

            for (Field field : fields) 
            {
                Class<?> t = field.getType();
                if(t == int.class)
                {
                    int layoutId = field.getInt(null);
                    String name = field.getName();

                    // Because /layout folder can have different layout files, 
                    // use some prefix to indicate which files are at the "activity level"
                    // This way the following IF controls which layout files make it in
                    if ( ! name.startsWith("activity_"))
                        continue;

                    Log.d("tag", "cur field = " + name + ", cur layoutId = " + layoutId );
                    layoutIds.add(layoutId);
                    layoutNameMap.put(layoutId, name);
                }
            }
        }
        catch (Exception e)
        {}
    }

}

(Add imports, modifiers, exception handlers, etc as needed) (根据需要添加导入,修饰符,异常处理程序等)

You cannot show them all at once in 1 window. 您无法在1个窗口中一次全部显示它们。 But you can have multiple files open at once. 但是您可以一次打开多个文件。

It is possible to have multiple files next to each other, but also as floating windows. 可能有多个文件彼此相邻,也有多个浮动窗口。

Like: 喜欢:

在此处输入图片说明

Now, since I transit to Android Studio, I see that there is such functionality. 现在,由于我过渡到Android Studio,因此看到了这种功能。 Its called "Navigation Editor" and one can reach it form in main menu: 它称为“导航编辑器”,可以在主菜单中找到它:

Tools > Android > Navigation Editor 工具> Android>导航编辑器

work exactly what I need. 正是我需要的。 Here is a print screen example: 这是一个打印屏幕示例:

导航编辑器示例

Here is only 2 activities, but I have some project that have more than 40 activities, and this help me to find me right one quickly. 这里只有2个活动,但是我有一些项目包含40多个活动,这有助于我快速找到合适的一个。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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