在Eclipse可视化编辑器定制的Andr​​oid浏览 [英] Custom Android Views in Eclipse Visual Editor

查看:324
本文介绍了在Eclipse可视化编辑器定制的Andr​​oid浏览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我经常依靠于自行设计的看法,如下面的例子。

In my applications, I often rely on custom build views, such as in the following example.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:background="@color/light_grey"
android:layout_height="match_parent" 
android:layout_width="fill_parent" >

<TextView 
 style="@style/CardTitle" 
 android:id="@+id/card_title"
 android:layout_height="wrap_content" 
 android:layout_width="fill_parent"      
 />  

<com.whiterabbit.cards.ui.AspectRatioImageView
    android:id="@+id/card_picture"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:layout_marginLeft="30dip"
    android:layout_marginRight="30dip"       
    android:src="@drawable/boss"
    />



<ListView 
    android:id="@+id/card_properties" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"

/>

现在的问题是,我不知道该怎么是否会直到我在一个真正的设备或仿真器上运行它正确地显示。此外,如果我发现了一些错误,我将不得不对其执行修改并再次部署应用程序,以查看是否变化和预期的一样工作。

The problem is, I don't know how if it will be displayed correctly until I run it on a real device or on the emulator. Moreover, if I found something wrong I would have to perform changes on it and deploy the app again to see if the changes worked as you expected.

这可能是一个漫长而枯燥的过程,特别是如果应用程序需要一定的相互作用去要检查活动。

This can be a long and boring process, especially if the application requires some interaction to get to the activity you want to check.

使用可视化编辑器不能正常工作,因为它无法加载自定义视图。

Using the visual editor doesn't work as it cannot load the custom view.

有另一种方式,以检查视图显示没有在整个应用程序中运行?

Is there another way to check how views are displayed without running across the whole application?

推荐答案

您可以在您的自定义视图做到这一点:

You can do this in your Custom View:

if(!isInEditMode()){
   // Your custom code that is not letting the Visual Editor draw properly
   // i.e. thread spawning or other things in the constructor
}

<一个href="http://developer.android.com/reference/android/view/View.html#isInEditMode%28%29">http://developer.android.com/reference/android/view/View.html#isInEditMode()

这允许您隐藏code从ADT插件XML阅读器,希望显示你的布局!

This allows you to hide code from the ADT Plugin XML Viewer and hopefully display you a layout!

View.isInEditMode()

View.isInEditMode()

指示是否这个观点是目前在编辑模式。视图是   通常在编辑模式下的时候,在开发工具上显示。对于   举例来说,如果这个观点是由一个可视化用户界面绘制   构建者,此方法应返回true。子类应检查   如果这种方法的返回值来提供不同的行为其   正常的行为可能会影响主机环境。对于   例如:类派生在其构造一个线程,绘图   code依赖于特定设备的特性等,这种方法通常是   检查自定义部件的图纸code。

Indicates whether this View is currently in edit mode. A View is usually in edit mode when displayed within a developer tool. For instance, if this View is being drawn by a visual user interface builder, this method should return true. Subclasses should check the return value of this method to provide different behaviors if their normal behavior might interfere with the host environment. For instance: the class spawns a thread in its constructor, the drawing code relies on device-specific features, etc. This method is usually checked in the drawing code of custom widgets.

这篇关于在Eclipse可视化编辑器定制的Andr​​oid浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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