fed*_*aol 11 eclipse android adt visual-editor android-layout
在我的应用程序中,我经常依赖自定义构建视图,例如在以下示例中.
<?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"
/>
Run Code Online (Sandbox Code Playgroud)
问题是,我不知道如果在真实设备或模拟器上运行它之前它是如何正确显示的.此外,如果我发现错误,我将不得不对其进行更改并再次部署应用程序以查看更改是否按预期工作.
这可能是一个漫长而枯燥的过程,特别是如果应用程序需要一些交互来访问您要检查的活动.
使用可视化编辑器不起作用,因为它无法加载自定义视图.
是否有另一种方法可以检查视图的显示方式而无需在整个应用程序中运行?
Blu*_*ell 54
您可以在自定义视图中执行此操作:
if(!isInEditMode()){
// Your custom code that is not letting the Visual Editor draw properly
// i.e. thread spawning or other things in the constructor
}
Run Code Online (Sandbox Code Playgroud)
http://developer.android.com/reference/android/view/View.html#isInEditMode()
这允许您隐藏ADT插件XML查看器中的代码,并希望显示一个布局!
View.isInEditMode()
指示此视图当前是否处于编辑模式.在开发人员工具中显示时,视图通常处于编辑模式.例如,如果此视图由可视用户界面构建器绘制,则此方法应返回true.如果子类的正常行为可能会干扰主机环境,则子类应检查此方法的返回值以提供不同的行为.例如:该类在其构造函数中生成一个线程,绘图代码依赖于特定于设备的功能等.此方法通常在自定义小部件的绘图代码中进行检查.