Eclipse Visual Editor中的自定义Android视图 [英] Custom Android Views in Eclipse Visual Editor

查看:180
本文介绍了Eclipse Visual Editor中的自定义Android视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我经常依赖自定义构建视图,例如在下面的例子中。

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
}

http://developer.android.com/reference/android/view/View.html#isInEditMode()

这允许您隐藏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。子类应检查此方法的
返回值,以提供不同的行为,如果它们的
正常行为可能会干扰主机环境。对于
实例:该类在其构造函数中生成一个线程,绘图
代码依赖于特定于设备的功能等。此方法通常是在自定义小部件的绘图代码中检查
。 / p>

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 Visual Editor中的自定义Android视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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